Created
May 16, 2018 05:47
-
-
Save vishalhalani/7e957469169b0f7c3e78d0b319d14eff to your computer and use it in GitHub Desktop.
Class to parse API error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by vishal.halani on 23-Jun-17. | |
*/ | |
public class ErrorUtil { | |
public static APIError parseError(Response<?> response) { | |
Converter<ResponseBody, APIError> converter = | |
RetrofitClient.getRetrofit() | |
.responseBodyConverter(APIError.class, new Annotation[0]); | |
APIError error; | |
try { | |
Log.e("ERROR UTIL","parseError: response Code=>"+response.code()); | |
//Timber.tag("ERROR UTIL").e("parseError: response Code=>" + response.code()); | |
error = converter.convert(response.errorBody()); | |
error.setErrorCode(response.code()); | |
} catch (Exception e) { | |
return new APIError(); | |
} | |
return error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment