slack-ruby / slack-ruby/slack-ruby-client
RFC: Web API error response_metadata is buried
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.3k
- Forks
- 222
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading lib/slack/web/faraday/response/raise_error.rb, where the response error becomes the SlackError message, and inspect how response.body is exposed. The issue proposes several possible API and configuration changes, so first confirm the desired behavior with maintainers; done would require an agreed design and corresponding coverage for verbose messages and response attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100