Skip to content

Instantly share code, notes, and snippets.

@kevin-madhu
Created April 11, 2018 15:44
Show Gist options
  • Save kevin-madhu/f1c199830182947ccdfac11801be05d7 to your computer and use it in GitHub Desktop.
Save kevin-madhu/f1c199830182947ccdfac11801be05d7 to your computer and use it in GitHub Desktop.
class CustomErrorWebExceptionHandler : AbstractErrorWebExceptionHandler() {
// Define constructor here
override fun getRoutingFunction(errorAttributes: ErrorAttributes): RouterFunction<ServerResponse> {
return RouterFunctions
.route<ServerResponse>(aPredicate, aHandler)
// .andRoute(anotherPredicate, anotherHandler)
.filter { request, next ->
try {
next.handle(request)
} catch (ex: Exception) {
when (ex) {
is ChangeSetPersister.NotFoundException -> ServerResponse.notFound().build()
else -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment