@Override public ApiErrorResponse<T> deserialize(JsonParser p) throws IOException, JsonParseException { T error = null; LocalizedText userMessage = null; expectStartObject(p); while (p.getCurrentToken() == JsonToken.FIELD_NAME) { String field = p.getCurrentName(); p.nextToken(); if ("error".equals(field)) { error = errSerializer.deserialize(p); } else if ("user_message".equals(field)) { userMessage = LocalizedText.STONE_SERIALIZER.deserialize(p); } else { skipValue(p); } } if (error == null) { throw new JsonParseException(p, "Required field \"error\" missing."); } ApiErrorResponse<T> value = new ApiErrorResponse<T>(error, userMessage); expectEndObject(p); return value; } }
case 403: try { ApiErrorResponse<AccessError> accessErrorResponse = new ApiErrorResponse.Serializer<AccessError>(AccessError.Serializer.INSTANCE) .deserialize(response.getBody()); if (accessErrorResponse.getUserMessage() != null) { message = accessErrorResponse.getUserMessage().toString(); case 422: try { ApiErrorResponse<PathRootError> pathRootErrorResponse = new ApiErrorResponse.Serializer<PathRootError>(Serializer.INSTANCE) .deserialize(response.getBody()); if (pathRootErrorResponse.getUserMessage() != null) { message = pathRootErrorResponse.getUserMessage().toString();
public static <T> DbxWrappedException fromResponse(StoneSerializer<T> errSerializer, HttpRequestor.Response response, String userId) throws IOException, JsonParseException { String requestId = DbxRequestUtil.getRequestId(response); ApiErrorResponse<T> apiResponse = new ApiErrorResponse.Serializer<T>(errSerializer) .deserialize(response.getBody()); T routeError = apiResponse.getError(); DbxGlobalCallbackFactory factory = DbxRequestUtil.sharedCallbackFactory; DbxWrappedException.executeBlockForObject(factory, userId, routeError); DbxWrappedException.executeOtherBlocks(factory, userId, routeError); return new DbxWrappedException(routeError, requestId, apiResponse.getUserMessage()); }