Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created October 28, 2013 14:30
Show Gist options
  • Save adohe-zz/7197688 to your computer and use it in GitHub Desktop.
Save adohe-zz/7197688 to your computer and use it in GitHub Desktop.
NetWork layer problem
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
Utility.log("statuscode", response.statusCode);
try {
if(response.statusCode != 200) {
return Response.error(new VolleyError("Network Error"));
} else {
String data = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
Utility.log("data", data);
T list = mGson.fromJson(data, new TypeToken<T>(){}.getType());
return Response.success(list, HttpHeaderParser.parseCacheHeaders(response));
}
/*String data = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
JSONObject jsonObject = new JSONObject(data);
if(Integer.valueOf(jsonObject.getJSONObject("Status").getString("Id")) != 0) {
return Response.error(new VolleyError(jsonObject.getJSONObject("Status").getString("Memo")));
} else {
return Response.success(mGson.fromJson(jsonObject.getJSONObject("Data").toString(), clazz), HttpHeaderParser.parseCacheHeaders(response));
}*/
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} /*catch (JSONException e) {
return null;
}*/
}
@Override
protected VolleyError parseNetworkError(VolleyError volleyError) {
return super.parseNetworkError(volleyError);
}
@Override
protected void deliverResponse(T t) {
listener.onResponse(t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment