-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
JSON Pointer resolve failure resulting in incorrect exception code #888
Comments
Thanks for the info! I'll check. |
The at function throws json::out_of_range.403 when a nonexistent object key is provided (just like the usual at function). This was not documented and users could assume json::out_of_range.404 would be thrown instead. - Updated documentation. - Added example code.
@cmannett85 Can you please have a look whether the updated documentation better describes the behavior of the function? |
@nlohmann, can you explain the difference between a 403 and 404 error? In the example code: // out_of_range.403
try
{
// try to use a JSON pointer to an nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer);
}
catch (json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.404
try
{
// try to use a JSON pointer that cannot be resolved
json::reference ref = j.at("/number/foo"_json_pointer);
}
catch (json::out_of_range& e)
{
std::cout << e.what() << '\n';
} In the latter example |
Take {"one": 1, "two": 2, "list": [1,2,3]} as example.
|
Ah, so a 403 is always thrown when a missing object member is requested, whilst a 404 is thrown when the JSON pointer is invalid (as opposed to 'malformed')? If so, why does the last example in your link throw a 404 instead of a 403 (as |
In the example, |
I finally understand! Your documentation update addresses the issue, so I'll close this issue. |
:) |
Prints:
According to the
json::out_of_range
andjson::at(const json_pointer&)
docs, a JSON pointer that cannot be resolved should return a 404, but it actually returns a 403.The text was updated successfully, but these errors were encountered: