|
26 | 26 | import com.linecorp.armeria.common.RequestHeaders; |
27 | 27 | import com.linecorp.armeria.common.annotation.Nullable; |
28 | 28 |
|
29 | | -final class ServerErrorHandlerDecorators { |
| 29 | +final class ErrorHandlerDecorators { |
30 | 30 |
|
31 | | - private static final List<DecoratingServerErrorHandlerFunction> decoratorFunctions = |
32 | | - ImmutableList.of(new CorsServerErrorHandler(), |
33 | | - new ContentPreviewServerErrorHandler()); |
| 31 | + private static final List<DecoratingErrorHandlerFunction> decoratorFunctions = |
| 32 | + ImmutableList.of(new CorsErrorHandler(), |
| 33 | + new ContentPreviewErrorHandler()); |
34 | 34 |
|
35 | | - private ServerErrorHandlerDecorators() {} |
| 35 | + private ErrorHandlerDecorators() {} |
36 | 36 |
|
37 | 37 | static ServerErrorHandler decorate(ServerErrorHandler delegate) { |
38 | 38 | ServerErrorHandler decorated = delegate; |
39 | | - for (DecoratingServerErrorHandlerFunction decoratorFunction : decoratorFunctions) { |
| 39 | + for (DecoratingErrorHandlerFunction decoratorFunction : decoratorFunctions) { |
40 | 40 | decorated = new DecoratingServerErrorHandler(decorated, decoratorFunction); |
41 | 41 | } |
42 | 42 | return decorated; |
43 | 43 | } |
44 | 44 |
|
| 45 | + static ServiceErrorHandler decorate(ServiceErrorHandler delegate) { |
| 46 | + ServiceErrorHandler decorated = delegate; |
| 47 | + for (DecoratingErrorHandlerFunction decoratorFunction : decoratorFunctions) { |
| 48 | + decorated = new DecoratingServiceErrorHandler(decorated, decoratorFunction); |
| 49 | + } |
| 50 | + return decorated; |
| 51 | + } |
| 52 | + |
45 | 53 | private static final class DecoratingServerErrorHandler implements ServerErrorHandler { |
46 | 54 |
|
47 | 55 | final ServerErrorHandler delegate; |
48 | | - final DecoratingServerErrorHandlerFunction decoratorFunction; |
| 56 | + final DecoratingErrorHandlerFunction decoratorFunction; |
49 | 57 |
|
50 | 58 | DecoratingServerErrorHandler(ServerErrorHandler delegate, |
51 | | - DecoratingServerErrorHandlerFunction decoratorFunction) { |
| 59 | + DecoratingErrorHandlerFunction decoratorFunction) { |
52 | 60 | this.delegate = delegate; |
53 | 61 | this.decoratorFunction = decoratorFunction; |
54 | 62 | } |
@@ -79,4 +87,32 @@ public AggregatedHttpResponse renderStatus(@Nullable ServiceRequestContext ctx, |
79 | 87 | return delegate.renderStatus(ctx, config, headers, status, description, cause); |
80 | 88 | } |
81 | 89 | } |
| 90 | + |
| 91 | + private static final class DecoratingServiceErrorHandler implements ServiceErrorHandler { |
| 92 | + |
| 93 | + final ServiceErrorHandler delegate; |
| 94 | + final DecoratingErrorHandlerFunction decoratorFunction; |
| 95 | + |
| 96 | + DecoratingServiceErrorHandler(ServiceErrorHandler delegate, |
| 97 | + DecoratingErrorHandlerFunction decoratorFunction) { |
| 98 | + this.delegate = delegate; |
| 99 | + this.decoratorFunction = decoratorFunction; |
| 100 | + } |
| 101 | + |
| 102 | + @Nullable |
| 103 | + @Override |
| 104 | + public HttpResponse onServiceException(ServiceRequestContext ctx, Throwable cause) { |
| 105 | + return decoratorFunction.onServiceException(delegate, ctx, cause); |
| 106 | + } |
| 107 | + |
| 108 | + @Nullable |
| 109 | + @Override |
| 110 | + public AggregatedHttpResponse renderStatus(ServiceRequestContext ctx, |
| 111 | + RequestHeaders headers, |
| 112 | + HttpStatus status, |
| 113 | + @Nullable String description, |
| 114 | + @Nullable Throwable cause) { |
| 115 | + return delegate.renderStatus(ctx, headers, status, description, cause); |
| 116 | + } |
| 117 | + } |
82 | 118 | } |
0 commit comments