appdotnet / api-spec

App.net API Documentation is on the web at https://developers.app.net. Source for these docs is in the new-docs branch here. Please use the issue tracker and submit pull requests! Help us build the real-time social service where users and developers come first, not advertisers.
https://developers.app.net
950 stars 98 forks source link

Include an error_slug for 403 error with missing scope #274

Open mattrubin opened 11 years ago

mattrubin commented 11 years ago

When I make a request to the API with a bad token, I get a meta response like this:

"meta": {
    "code": 401,
    "error_id": "d7099806b6f1421980a6f44088f2b38c$b6ce313414de7e9de45deb4ba34c56a1",
    "error_message": "Call requires authentication: User has not authorized this client or has revoked access.",
    "error_slug": "not-authorized"
}

By checking the error_slug, I can automatically respond to the error by prompting the user to reauthorize.

When I try to call an API method for which I don't have the required scope, I receive the following meta response:

"meta": {
    "code": 403,
    "error_id": "dc677e02201c449ebf88d01fdf99cccf$a51ffdf14f5b267f333a829f92bf09d8",
    "error_message": "Forbidden: You need the following scopes: follow"
}

I would like to detect which scope is missing and automatically prompt the user to authorize with that scope. I can do this currently by parsing the error_message, but I'd like a more reliable way to recognize this error and determine which scopes I need. Something like:

"meta": {
    ...
    "error_slug": "missing-scopes",
    "scopes-required": [
        "follow"
    ]
}