Not a bug PrintableException treated as unknown_api_error in the API response

MilkyMeda

Active member
Affected version
2.2.4
PrintableException is user-accessible. If this exception gets thrown somewhere along in the API it is marked as unknown_api_error. This makes it difficult to determine whether the user should see this error or not.
 
I can't reproduce this. You may need to provide us with a reduced test case to so we can see more details about the situation you're running into.

I tested it with the following code:

Code:
throw new \XF\PrintableException(\XF::phrase('do_not_have_permission'));

The API response was:

Code:
{
    "errors": [
        {
            "code": "do_not_have_permission",
            "message": "You do not have permission to view this page or perform this action.",
            "params": []
        }
    ]
}

If your code is not using a phrase, then sending unknown_api_error is expected. You would either need to use a phrase or use an API-specific method to expose an error code separately from the printable message.
 
Top Bottom