Skip to content

Instantly share code, notes, and snippets.

@brunapereira
Last active May 11, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunapereira/7e0ed5e3fc6de0825228557f0b1662bb to your computer and use it in GitHub Desktop.
Save brunapereira/7e0ed5e3fc6de0825228557f0b1662bb to your computer and use it in GitHub Desktop.
Exception Handler
@RestControllerAdvice
@Order(0)
class VendasExceptionHandler {
@ResponseStatus(BAD_REQUEST)
@ExceptionHandler(ProductNotFound::class)
fun onProductNotFound(e: ProductNotFound): ApiError {
log.error("error=product not found", e)
return ApiError(code = "PRODUCT_NOT_FOUND", message = e.message ?: "")
}
// other exceptions threatments..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment