-
-
Notifications
You must be signed in to change notification settings - Fork 226
Description
In some of the more recent Web API methods the most relevant error information is given in the response_metadata. For instance here's an example of Slack's response body for a bad call to views.open:
{
"ok": false,
"error": "invalid_arguments",
"response_metadata": {
"messages": [
"[ERROR] missing required field: title [json-pointer:/view]",
"[ERROR] missing required field: blocks [json-pointer:/view]",
"[ERROR] missing required field: type [json-pointer:/view]"
]
}
}The error value of invalid_arguments is basically useless on its own — it's necessary to look at the response_metadata to understand the problem with the request.
Currently this library pulls out the error value and uses this for the message on SlackError (here). It's possible to access the reseponse_metadata with slack_error.response.body.response_metadata. However my problem is that when an error is raised my logs only show the error, because that is the message (and as far as I can tell, raise prints Class: message).
My goal is to get the response_metadata into my logs. Here's one idea that I have for a feature in this library that would achieve that:
- Add a config option for verbose Web API errors (
verbose_web_api_errors?). - If this config option is set then the
messageonSlackErrorwill be the entire body as JSON, rather than just theerror. - The option would default to false so as to not break anyone's code.
SlackErrorwould also gain a new attribute, perhapserror, which would be the value oferrorfrom Slack's response, so that this is easily accessed even when the verbose option is being used.- For completeness,
SlackErrorwould also gain a new attributeresponse_metadatacontaining just theresponse_metadata(as a hash-like object).
What do you think of this approach? I don't know much about logging, so maybe there's a better approach to this, either within this library or simply in my own app.