String error = cause.getMessage();
error = (null == error) ? "Unknown error" : error;
if (cause instanceof InvalidParamsException) {
log.error(cause.getMessage());
return gson.toJson(new Error(error, Error.INVALID_PARAMS));
} else if (cause instanceof MethodNotFoundException) {
log.error(cause.getMessage());
return gson.toJson(new Error(error, Error.METHOD_NOT_FOUND));
} else if (cause instanceof InternalErrorException) {
log.error("Internal Error", cause);
return gson.toJson(new Error(error, Error.INTERNAL_ERROR));
} else if (cause instanceof AuthorizationErrorException) {
log.error("Authorization Error", cause);
return gson.toJson(new Error(error, Error.AUTHORIZATION_ERROR));
} else if (cause instanceof LimitReachedException) {
log.error("Max records limit reached", cause);
return gson.toJson(new Error(error, Error.LIMIT_REACHED_ERROR));
}
else {
log.error("Unknown error occurred while processing the request", cause);
return gson.toJson(new Error(error, Error.FATAL));
}
}