From 0ce88caa65513934b01af6d2eccd90d722ccfbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 15 Sep 2016 23:01:40 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20even=20try=20to=20deserialize?= =?UTF-8?q?=20non-JSON=20response=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MapboxStatic/Snapshot.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MapboxStatic/Snapshot.swift b/MapboxStatic/Snapshot.swift index 4ce117f..d4dfce3 100644 --- a/MapboxStatic/Snapshot.swift +++ b/MapboxStatic/Snapshot.swift @@ -493,9 +493,13 @@ public class Snapshot: NSObject { var json: JSONDictionary = [:] var image: Image? if let data = data { - do { - json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? JSONDictionary ?? json - } catch { + if response?.MIMEType == "application/json" { + do { + json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? JSONDictionary ?? json + } catch { + assert(false, "Invalid data") + } + } else { image = Image(data: data) } }