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


    "message":"Not Found",
    "_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


    "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.