question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ProblemDetails: make httpstatuses problem types optional

See original GitHub issue

I just installed the ProblemDetails middleware, which was really easy by the way, and this is my first feedback.

The first thing I tried after installation was doing a GET for a non-existent API which would normally result in a 404 and an empty body. Instead I got a 404 and a problem detail document. Great!

{
    "type": "https://httpstatuses.com/404",
    "title": "Not Found",
    "status": 404,
    "detail": null,
    "instance": null
}

What I didn’t expect was the problem URI that links to httpstatuses.com. I checked the RFC and it seems to agree with me that you shouldn’t have a custom problem URI for generic errors.

(…) truly generic problems – i.e., conditions that could potentially apply to any resource on the Web – are usually better expressed as plain status codes. For example, a “write access disallowed” problem is probably unnecessary, since a 403 Forbidden status code in response to a PUT request is self-explanatory.

https://tools.ietf.org/html/rfc7807#section-4

This specification reserves the use of one URI as a problem type:

The “about:blank” URI [RFC6694], when used as a problem type, indicates that the problem has no additional semantics beyond that of the HTTP status code.

https://tools.ietf.org/html/rfc7807#section-4.2

So my recommendation is to just leave off the problem type and let it default to about:blank for generic errors. At least make it configurable using ProblemDetailsOptions.

{
    "title": "Not Found",
    "status": 404,
    "detail": null,
    "instance": null
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sliekenscommented, Oct 8, 2018

Here’s how I use it:

options.MapStatusCode = statusCode => new StatusCodeProblemDetails(statusCode)
{
    Type = "about:blank"
};

or

options.MapStatusCode = statusCode => new StatusCodeProblemDetails(statusCode)
{
    Type = null // not recommended if JsonSerializerSettings.NullValueHandling is "Include"
};
0reactions
sliekenscommented, Oct 7, 2018

Perfect, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP API Problem Details in ASP.NET Core
“problem detail” as a way to carry machine-readable details of errors in a HTTP response to avoid the need to define new error...
Read more >
Spring Boot 3 : Error Responses using Problem Details for ...
Assume we have the following REST API endpoints to create a bookmark and fetch a bookmark by id. @RestController @RequestMapping("/api/bookmarks ...
Read more >
Change default "type" for problem detail API in Spring Boot?
ProblemDetail is new in Spring Framework 6 (Spring Boot 3) and requires Java17 so many classes have moved. I have added the zalando...
Read more >
A standard way of specifying errors in HTTP API responses
In this post I've tried to show you a way of specifying errors in HTTP API responses using Problem details and how to...
Read more >
Building Standardized API Error Responses in Spring Boot ...
In this tutorial, I'll show you how to implement error handling with Problem Details in a Spring Boot application through comprehensive examples ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found