@@ -82,16 +82,28 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
82
82
private fun exceptionToResponseEntity (e : Exception , input : APIGatewayProxyRequestEvent ) =
83
83
when (e) {
84
84
is ApiException -> e.toResponseEntity(this ::createErrorBody)
85
- .also { log.info( " Caught api error while handling ${ input.httpMethod} ${input.path} - $e " ) }
85
+ .also { logApiException(e, input) }
86
86
else -> exceptionToResponseEntity(e)
87
- .also {
88
- log.error(" Caught exception handling ${input.httpMethod} ${input.path} - $e " , e)
89
- }
87
+ .also { logUnknownException(e, input) }
90
88
}
91
89
92
90
private fun missingPermissions (input : APIGatewayProxyRequestEvent , routerFunction : RouterFunction <Any , Any >) =
93
91
! permissionHandlerSupplier()(input).hasAnyRequiredPermission(routerFunction.requestPredicate.requiredPermissions)
94
92
93
+ /* *
94
+ * Hook to be able to override the way ApiExceptions are logged.
95
+ */
96
+ open fun logApiException (e : ApiException , input : APIGatewayProxyRequestEvent ) {
97
+ log.info(" Caught api error while handling ${input.httpMethod} ${input.path} - $e " )
98
+ }
99
+
100
+ /* *
101
+ * Hook to be able to override the way non-ApiExceptions are logged.
102
+ */
103
+ open fun logUnknownException (e : Exception , input : APIGatewayProxyRequestEvent ) {
104
+ log.error(" Caught exception handling ${input.httpMethod} ${input.path} - $e " , e)
105
+ }
106
+
95
107
open fun serializationHandlers (): List <SerializationHandler > = listOf (
96
108
JsonSerializationHandler (objectMapper)
97
109
)
@@ -162,6 +174,11 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
162
174
163
175
private fun createUnprocessableEntityErrorBody (error : UnprocessableEntityError ): Any = createUnprocessableEntityErrorBody(listOf (error))
164
176
177
+ /* *
178
+ * Hook to customize the way non-ApiExceptions are converted to ResponseEntity.
179
+ *
180
+ * Some common exceptions are already handled in the default implementation.
181
+ */
165
182
open fun exceptionToResponseEntity (ex : Exception ) =
166
183
when (ex) {
167
184
is JsonParseException -> ResponseEntity (
0 commit comments