use of org.brunocvcunha.instagram4j.requests.payload.StatusResult in project instagram4j by brunocvcunha.
the class InstagramRequest method parseJson.
/**
* Parses Json into type, considering the status code
* @param statusCode HTTP Status Code
* @param str Entity content
* @param clazz Class
* @return Result
*/
@SneakyThrows
public <U> U parseJson(int statusCode, String str, Class<U> clazz) {
if (clazz.isAssignableFrom(StatusResult.class)) {
// TODO: implement a better way to handle exceptions
if (statusCode == HttpStatus.SC_NOT_FOUND) {
StatusResult result = (StatusResult) clazz.newInstance();
result.setStatus("error");
result.setMessage("SC_NOT_FOUND");
return (U) result;
} else if (statusCode == HttpStatus.SC_FORBIDDEN) {
StatusResult result = (StatusResult) clazz.newInstance();
result.setStatus("error");
result.setMessage("SC_FORBIDDEN");
return (U) result;
}
}
return parseJson(str, clazz);
}
Aggregations