-
-
Notifications
You must be signed in to change notification settings - Fork 158
Distinguish between NotFound resource and NotFound route #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
All errors should be returned in a json:api error document. Otherwise how would a json:api client know how to handle them? Can you provide more details around your specific situation? You’re getting a 404 because you’re returning null from your controller? Or an exception isn’t being handled properly? Or are you referring to the stack trace? That can be disabled outside of the development environment. |
I'm really just wanting anything returned. lol. Here is what I have so far:
The whole startup.cs, if you're curious: https://github.com/sillsdev/appbuilder-portal/blob/master/source/OptimaJet.DWKit.StarterApplication/Startup.cs#L96 |
Does a user with the id “current-user” exist in the database? I don’t see a custom repository that would alter the default behavior. And by default it will just look for a user with the specified id in the database. |
there is no "current-user" user atm, |
Per the specification:
However, you can always alter this behavior by overriding the controller method or implementing the necessary service or repository interfaces: |
so for clarification, a middleware to provide more information on all errors is out of scope for this project? |
You can always write your own middleware. But, in general, the most detailed information about an error is available at the site where the error occurs. It would be difficult to provide useful information using generalized middleware. However, for this example, you could create a general controller that overrides the {
"errors": [
{
"title": "Resource 'users' with id 'current-user' was not found.",
"status": "404"
}
]
} Is that what you're thinking? To get this kind of behavior, you could override the controller like so: namespace Optimajet.DWKit.StarterApplication.Controllers
{
private readonly IResourceService<User> _userService;
public class UsersController : JsonApiController<User>
{
public UsersController(
IJsonApiContext jsonApiContext,
IResourceService<User> userService,
ILoggerFactory loggerFactory)
: base(jsonApiContext, resourceService, loggerFactory)
{
_userService = userService;
}
[HttpGet("{id}")]
public override async Task<IActionResult> GetAsync(TId id)
{
var entity = await _userService.GetAsync(id);
if (entity == null)
return Error(new Error(404, $"Resource 'users' with id '{id}' was not found."));
return Ok(entity);
}
}
} To achieve this using a general middleware, you'd need to:
You should be able to do this using an if(ctx.Result is NotFoundResult) {
// handle the 404 case
} But because this is outside the context of the actual result evaluation, we're really inferring what 404 means and can't provide any information that is more useful than a 404 status code itself. |
@NullVoxPopuli I'm closing this because I'm not sure I have any work to takeaway from this. Feel free to reopen if you're interested in continuing the discussion. |
re-opening because I want to track a solution for distinguishing between 404 route not found and 404 resource (with id) not found. |
Fixed by #714. |
does it make sense to return JSONAPI errors on uncaught server errors?
for example, I'm getting a 404, cause I'm bad at databasing, and the response body is empty.
imo, it'd be great if there was a response body with the error message text / and or exception class.
maybe this'd be a development mode only thing? idk.
The text was updated successfully, but these errors were encountered: