|
20 | 20 | */ |
21 | 21 | package com.inrupt.client; |
22 | 22 |
|
| 23 | +import java.net.URI; |
| 24 | + |
23 | 25 | /** |
24 | 26 | * A runtime exception representing an HTTP error response carrying a structured representation of the problem. The |
25 | 27 | * problem description is embedded in a {@link ProblemDetails} instance. |
26 | 28 | */ |
27 | 29 | public class ClientHttpException extends InruptClientException { |
28 | 30 | private final ProblemDetails problemDetails; |
| 31 | + private final URI uri; |
| 32 | + private final int statusCode; |
| 33 | + private final String body; |
| 34 | + private final transient Headers headers; |
29 | 35 |
|
30 | 36 | /** |
31 | 37 | * Create a ClientHttpException. |
32 | | - * @param problemDetails the {@link ProblemDetails} instance |
33 | 38 | * @param message the exception message |
| 39 | + * @param uri the error response URI |
| 40 | + * @param statusCode the error response status code |
| 41 | + * @param headers the error response headers |
34 | 42 | */ |
35 | | - public ClientHttpException(final ProblemDetails problemDetails, final String message) { |
| 43 | + public ClientHttpException(final String message, final URI uri, final int statusCode, |
| 44 | + final Headers headers, final String body) { |
36 | 45 | super(message); |
37 | | - this.problemDetails = problemDetails; |
| 46 | + this.uri = uri; |
| 47 | + this.statusCode = statusCode; |
| 48 | + this.headers = headers; |
| 49 | + this.body = body; |
| 50 | + this.problemDetails = ProblemDetails.fromErrorResponse(statusCode, headers, body.getBytes()); |
38 | 51 | } |
39 | 52 |
|
40 | 53 | /** |
41 | | - * Create a ClientHttpException. |
42 | | - * @param problemDetails the {@link ProblemDetails} instance |
43 | | - * @param message the exception message |
44 | | - * @param cause a wrapped exception cause |
| 54 | + * Retrieve the URI associated with this exception. |
| 55 | + * |
| 56 | + * @return the uri |
| 57 | + */ |
| 58 | + public URI getUri() { |
| 59 | + return uri; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Retrieve the status code associated with this exception. |
| 64 | + * |
| 65 | + * @return the status code |
| 66 | + */ |
| 67 | + public int getStatusCode() { |
| 68 | + return statusCode; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Retrieve the headers associated with this exception. |
| 73 | + * |
| 74 | + * @return the headers |
45 | 75 | */ |
46 | | - public ClientHttpException(final ProblemDetails problemDetails, final String message, final Exception cause) { |
47 | | - super(message, cause); |
48 | | - this.problemDetails = problemDetails; |
| 76 | + public Headers getHeaders() { |
| 77 | + return headers; |
49 | 78 | } |
50 | 79 |
|
| 80 | + /** |
| 81 | + * Retrieve the body associated with this exception. |
| 82 | + * |
| 83 | + * @return the body |
| 84 | + */ |
| 85 | + public String getBody() { |
| 86 | + return body; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Retrieve the {@link ProblemDetails} instance describing the HTTP error response. |
| 91 | + * @return the problem details object |
| 92 | + */ |
51 | 93 | public ProblemDetails getProblemDetails() { |
52 | 94 | return this.problemDetails; |
53 | 95 | } |
| 96 | + |
54 | 97 | } |
0 commit comments