|
23 | 23 | * @author Daniel DeGroff
|
24 | 24 | */
|
25 | 25 | public class ExceptionHandlerContext {
|
26 |
| - public Logger logger; |
| 26 | + private final Logger logger; |
27 | 27 |
|
28 |
| - public HTTPRequest request; |
| 28 | + private final HTTPRequest request; |
29 | 29 |
|
30 |
| - public int statusCode; |
| 30 | + private final Throwable throwable; |
31 | 31 |
|
32 |
| - public Throwable throwable; |
| 32 | + private int statusCode; |
33 | 33 |
|
34 | 34 | public ExceptionHandlerContext(Logger logger, HTTPRequest request, int statusCode, Throwable throwable) {
|
35 | 35 | this.logger = logger;
|
36 |
| - this.request = request; // may be null |
| 36 | + this.request = request; |
37 | 37 | this.statusCode = statusCode;
|
38 | 38 | this.throwable = throwable;
|
39 | 39 | }
|
| 40 | + |
| 41 | + /** |
| 42 | + * This is provided for convenience, but you may wish to use your own logger. |
| 43 | + * |
| 44 | + * @return the optional logger to use in the exception handler. |
| 45 | + */ |
| 46 | + public Logger getLogger() { |
| 47 | + return logger; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * This may be useful if you wish to know additional context of the exception such as the URI of the current HTTP request. |
| 52 | + * <p> |
| 53 | + * Modifications to this object will have no effect on current or futures requests. |
| 54 | + * |
| 55 | + * @return the current HTTP request, or null if this exception was taking prior to constructing the HTTP request. This is unlikely but |
| 56 | + * please account for this value being null. |
| 57 | + */ |
| 58 | + public HTTPRequest getRequest() { |
| 59 | + return request; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @return the desired status code for the HTTP response. |
| 64 | + */ |
| 65 | + public int getStatusCode() { |
| 66 | + return statusCode; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Suggest a status code for the HTTP response. This value will be used unless the response has already been committed meaning bytes have |
| 71 | + * already been written to the client and the HTTP server is not able to modify the response code. |
| 72 | + * |
| 73 | + * @param statusCode the desired status code to set on the HTTP response. |
| 74 | + */ |
| 75 | + public void setStatusCode(int statusCode) { |
| 76 | + this.statusCode = statusCode; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * |
| 81 | + * @return the unexpected exception to handle |
| 82 | + */ |
| 83 | + public Throwable getThrowable() { |
| 84 | + return throwable; |
| 85 | + } |
40 | 86 | }
|
0 commit comments