Micronaut Error Responses with Problem+JSON

problem+json is my preferred way of formatting API errors and it is easy to use it in a Micronaut Application.

A request to a non existing route:

curl -i locahost:8080/api/v1/bogus

returns:

{
    "message":"Not Found",
    "_links":{"self":{"href":"/api/v1/bogus","templated":false}},
    "_embedded":{"errors":[{"message":"Page Not Found"}]}
}

The previous payload is formatted with vnd.error. The response content type is application/json.

If you add the dependency io.micronaut.problem:micronaut-problem-json, the maven coordinate of Micronaut Problem JSON, the same request:

curl -i locahost:8080/api/v1/bogus

returns:

{
    "type":"about:blank",
    "status":404,
    "detail":"Page Not Found"
}

Moreover, the response content type is application/problem+json.

Micronaut Problem JSON helps you produce application/problem+json responses from a Micronaut application. It connects the Problem library and Micronaut Error Formatting capabilities.

My next events:
๐Ÿ—“ May 27 09:00 AWS Dublin - Micronaut and AWS Lambda
๐Ÿ—“ Jul 20 09:00 Workshop Security in the Micronaut Framework
๐Ÿ—“ Sep 20 09:00 JCON Online 2022 - Getting Started with the Micronaut Framework
๐Ÿ—“ Sep 23 09:00 JCON Online 2022 - Micronautยฎ Framework and Microstream Java-native persistence engine

Tags: #micronaut #problem #vnd
Sep 2021, 28.