Skip to content

Commit a8b704e

Browse files
committed
add a null check to tileJson for missing tilejson data
1 parent 2400f32 commit a8b704e

File tree

1 file changed

+39
-34
lines changed
  • Runtime/Mapbox/BaseModule/Data/Platform/TileJSON

1 file changed

+39
-34
lines changed

Runtime/Mapbox/BaseModule/Data/Platform/TileJSON/TileJSON.cs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,54 @@
55

66
namespace Mapbox.BaseModule.Data.Platform.TileJSON
77
{
8-
public class TileJSON
9-
{
8+
public class TileJSON
9+
{
1010

11-
private IFileSource _fileSource;
12-
private int _timeout;
11+
private IFileSource _fileSource;
12+
private int _timeout;
1313

1414

15-
public IFileSource FileSource { get { return _fileSource; } }
15+
public IFileSource FileSource { get { return _fileSource; } }
1616

1717

18-
public TileJSON(IFileSource fileSource, int timeout)
19-
{
20-
_fileSource = fileSource;
21-
_timeout = timeout;
22-
}
18+
public TileJSON(IFileSource fileSource, int timeout)
19+
{
20+
_fileSource = fileSource;
21+
_timeout = timeout;
22+
}
2323

2424

25-
public IAsyncRequest Get(string tilesetName, Action<TileJSONResponse> callback)
26-
{
27-
string url = string.Format(
28-
"{0}v4/{1}.json?secure"
29-
, Constants.Map.BaseAPI
30-
, tilesetName
31-
);
25+
public IAsyncRequest Get(string tilesetName, Action<TileJSONResponse> callback)
26+
{
27+
string url = string.Format(
28+
"{0}v4/{1}.json?secure"
29+
, Constants.Map.BaseAPI
30+
, tilesetName
31+
);
3232

33-
return _fileSource.Request(
34-
url
35-
, (Response response) =>
36-
{
37-
string json = Encoding.UTF8.GetString(response.Data);
38-
TileJSONResponse tileJSONResponse = JsonConvert.DeserializeObject<TileJSONResponse>(json);
39-
if (tileJSONResponse != null)
40-
{
41-
tileJSONResponse.Source = tilesetName;
42-
}
43-
callback(tileJSONResponse);
44-
}
45-
, _timeout
46-
);
47-
}
33+
return _fileSource.Request(
34+
url
35+
, (Response response) =>
36+
{
37+
if (response != null && response.Data != null && response.Data.Length > 0)
38+
{
39+
string json = Encoding.UTF8.GetString(response.Data);
40+
TileJSONResponse tileJSONResponse = JsonConvert.DeserializeObject<TileJSONResponse>(json);
41+
if (tileJSONResponse != null)
42+
{
43+
tileJSONResponse.Source = tilesetName;
44+
}
45+
callback(tileJSONResponse);
46+
}
4847

48+
callback(null);
49+
}
50+
, _timeout
51+
);
52+
}
4953

5054

5155

52-
}
53-
}
56+
57+
}
58+
}

0 commit comments

Comments
 (0)