public static String getFirstHeader(HttpRequestor.Response response, String name) throws BadResponseException { List<String> values = response.getHeaders().get(name); if (values == null || values.isEmpty()) { throw new BadResponseException(getRequestId(response), "missing HTTP header \"" + name + "\""); } return values.get(0); }
public static <T> T readJsonFromResponse(JsonReader<T> reader, HttpRequestor.Response response) throws BadResponseException, NetworkIOException { try { return reader.readFully(response.getBody()); } catch (JsonReadException ex) { String requestId = getRequestId(response); throw new BadResponseException(requestId, "error in response JSON: " + ex.getMessage(), ex); } catch (IOException ex) { throw new NetworkIOException(ex); } }
private /*@Nullable*/ChunkedUploadState chunkedUploadCheckForOffsetCorrection(HttpRequestor.Response response) throws DbxException { if (response.getStatusCode() != 400) return null; byte[] data = DbxRequestUtil.loadErrorBody(response); try { return ChunkedUploadState.Reader.readFully(data); } catch (JsonReadException ex) { // Couldn't parse out an offset correction message. Treat it like a regular HTTP 400 then. String requestId = DbxRequestUtil.getRequestId(response); throw new BadRequestException(requestId, DbxRequestUtil.parseErrorBody(requestId, 400, data)); } }
ChunkedUploadState correctedState = chunkedUploadCheckForOffsetCorrection(response); if (correctedState != null) { String requestId = DbxRequestUtil.getRequestId(response); throw new BadResponseException(requestId, "Got offset correction response on first chunk."); String requestId = DbxRequestUtil.getRequestId(response); throw new BadResponseException(requestId, "Got a 404, but we didn't send an upload_id"); String requestId = DbxRequestUtil.getRequestId(response); throw new BadResponseException(requestId, "Sent " + chunkSize + " bytes, but returned offset is " + returnedState.offset);
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()); }
}; HttpRequestor.Response response = chunkedUploadCommon(params, chunkSize, writer); String requestId = DbxRequestUtil.getRequestId(response); try { ChunkedUploadState correctedState = chunkedUploadCheckForOffsetCorrection(response);
public static DbxException unexpectedStatus(HttpRequestor.Response response, String userId) throws NetworkIOException, BadResponseException { String requestId = getRequestId(response); String message = null; DbxException networkError;
String requestId = DbxRequestUtil.getRequestId(response); throw new BadResponseException(requestId, "Bad JSON in response: " + ex, ex);