Local exception handler

    1. HttpResponse<JsonError> jsonError(HttpRequest request, JsonParseException jsonParseException) { (1)
    2. JsonError error = new JsonError("Invalid JSON: " + jsonParseException.getMessage()) (2)
    3. .link(Link.SELF, Link.of(request.getUri()))
    4. HttpResponse.<JsonError>status(HttpStatus.BAD_REQUEST, "Fix Your JSON")
    5. .body(error) (3)

    Local exception handler

    1. @Error(status = HttpStatus.NOT_FOUND)
    2. public HttpResponse<JsonError> notFound(HttpRequest request) { (1)
    3. JsonError error = new JsonError("Person Not Found") (2)
    4. .link(Link.SELF, Link.of(request.getUri()));
    5. return HttpResponse.<JsonError>notFound()
    6. .body(error); (3)

    Local status handler

    1. @Error(status = HttpStatus.NOT_FOUND)
    2. fun notFound(request: HttpRequest<*>): HttpResponse<JsonError> { (1)
    3. val error = JsonError("Person Not Found") (2)
    4. .link(Link.SELF, Link.of(request.uri))
    5. return HttpResponse.notFound<JsonError>()
    6. .body(error) (3)
    1The declares which HttpStatus error code to handle (in this case 404)
    2A instance is returned for all 404 responses
    3An NOT_FOUND response is returned