1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 package software.amazon.awssdk.crt.s3; 6 7 import software.amazon.awssdk.crt.http.HttpHeader; 8 9 public class S3FinishedResponseContext { 10 private final int errorCode; 11 private final int responseStatus; 12 private final byte[] errorPayload; 13 private final ChecksumAlgorithm checksumAlgorithm; 14 private final boolean didValidateChecksum; 15 16 private final Throwable cause; 17 private final HttpHeader[] errorHeaders; 18 19 /* 20 * errorCode The CRT error code 21 * responseStatus statusCode of the HTTP response 22 * errorPayload body of the error response. Can be null if the request completed successfully 23 * checksumAlgorithm, the algorithm used to validate the Body, None if not validated 24 * didValidateChecksum which is true if the response was validated. 25 * cause of the error such as a Java exception in a callback. Maybe NULL if there was no exception in a callback. 26 */ S3FinishedResponseContext(final int errorCode, final int responseStatus, final byte[] errorPayload, final ChecksumAlgorithm checksumAlgorithm, final boolean didValidateChecksum, Throwable cause, final HttpHeader[] errorHeaders)27 S3FinishedResponseContext(final int errorCode, final int responseStatus, final byte[] errorPayload, final ChecksumAlgorithm checksumAlgorithm, final boolean didValidateChecksum, Throwable cause, final HttpHeader[] errorHeaders) { 28 this.errorCode = errorCode; 29 this.responseStatus = responseStatus; 30 this.errorPayload = errorPayload; 31 this.checksumAlgorithm = checksumAlgorithm; 32 this.didValidateChecksum = didValidateChecksum; 33 this.cause = cause; 34 this.errorHeaders = errorHeaders; 35 } 36 getErrorCode()37 public int getErrorCode() { 38 return this.errorCode; 39 } 40 41 /* 42 * If the request didn't receive a response due to a connection 43 * failure or some other issue the response status will be 0. 44 */ getResponseStatus()45 public int getResponseStatus() { 46 return this.responseStatus; 47 } 48 49 /* 50 * In the case of a failed http response get the payload of the response. 51 */ getErrorPayload()52 public byte[] getErrorPayload() { 53 return this.errorPayload; 54 } 55 56 /* 57 * if no checksum is found, or the request finished with an error the Algorithm will be None, 58 * otherwise the algorithm will correspond to the one attached to the object when uploaded. 59 */ getChecksumAlgorithm()60 public ChecksumAlgorithm getChecksumAlgorithm() { 61 return this.checksumAlgorithm; 62 } 63 isChecksumValidated()64 public boolean isChecksumValidated() { 65 return this.didValidateChecksum; 66 } 67 68 /** 69 * Cause of the error, such as a Java exception from a callback. May be NULL if there was no exception in a callback. 70 * 71 * @return throwable 72 */ getCause()73 public Throwable getCause() { 74 return cause; 75 } 76 77 /** 78 * In the case of a failed HTTP response, get the headers of the response. May be NULL. 79 * 80 * @return array of headers 81 */ getErrorHeaders()82 public HttpHeader[] getErrorHeaders() { 83 return errorHeaders; 84 } 85 } 86