Skip to content
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

Treat 403 errors differently when due to lack of API support or API request limit exceeded #29

Closed
mike4aday opened this issue Mar 13, 2017 · 10 comments
Assignees
Labels

Comments

@mike4aday
Copy link
Owner

mike4aday commented Mar 13, 2017

For example, 403 error caused by Professional Edition without API should be handled differently (e.g. error exposed to end user) than other causes, which result in re-authentication and re-authorization via Salesforce-hosted form. See also Issue #27

@ghost
Copy link

ghost commented Mar 13, 2017

Adding some context: Availability of API access is one qualifier. I believe the availability of the service (OAuth) should be one too. Getting the user the pointed message about how to solve the problem is critical. 'User not authenticated' is too broad and forces the user to re-try with no success and causes developers to question their code unnecessarily. Improving the error messages to : 'OAuth services unavailable, please check trust-site (?) for status', or 'API services not available for your Edition' etc. would be mush appreciated.

@mike4aday
Copy link
Owner Author

mike4aday commented Mar 13, 2017

@pbrondum Salesforce will tell us, in the error message field returned in addition to the 403 status code, that the API is not enabled for the org. But other root causes for a 403 error should probably force a re-login, which Swiftly Salesforce currently does.

In other words: a 401 error should always result in re-login via the Salesforce-hosted form; and a 403 error should almost always result in re-login, unless it's due to the fact that API is not enabled for the org and the error message so indicates.

Are you seeing any other errors that shouldn't automatically indicate that re-login is called for?

@ghost
Copy link

ghost commented Mar 14, 2017 via email

@mike4aday
Copy link
Owner Author

@pbrondum in other words, the framework would keep track so that in the event of repeated failures, rather than trying yet again, an error message would get 'surfaced' to the user, i.e. a developer-configurable number of retries before giving up?

In the situation you describe, it sounds like there's a more serious, server-side failure that's difficult to discern on the client side without keeping track of past results, and examining a series of failures within some given timeframe. That adds a lot complexity and requires logic on the client side to discover something that's not working as designed (by Salesforce).

What error messages - in addition to the 403 status code - are you receiving?

@ghost
Copy link

ghost commented Mar 14, 2017 via email

@mike4aday
Copy link
Owner Author

mike4aday commented Mar 14, 2017

@pbrondum

  • Swiftly Salesforce does not automatically repeat the request with the same credentials in the event of 403 error. Instead, it turns over control to Salesforce, via the OAuth 2 user-agent flow, for authentication and authorization, in order to obtain new tokens.

  • Salesforce typically returns a JSON payload, with error code and message, along with the 403 HTTP response code. It will help if you can provide the content of that payload.

  • Unavailable service should result in error code 503, rather than 403. Swiftly Salesforce would surface that error, and the developer can handle it as appropriate.

  • If the Salesforce server is erroneously responding with 403 when the underlying cause is, for example, unavailable service, then that has to be addressed differently, since it's beyond the scope of a client framework to second guess a server that doesn't comply with the HTTP protocol. If you can provide me date, time, and JSON payload. I will file a Salesforce bug.

@mike4aday
Copy link
Owner Author

mike4aday commented Mar 17, 2017

@pbrondum another reason for 403 response, unrelated to credentials and where it doesn't make sense to attempt to re-authenticate right away, is when the response payload contains 'REQUEST_LIMIT_EXCEEDED' -- exceeding the API request limit might also explain what you see for ~30 minutes on some weekends, especially if you're doing a lot of testing & dev within the preceding 24 hours.

I'll update the title of this issue to include both cases: API not available (e.g. Prof. Edition), and API request limit exceeded.

@mike4aday mike4aday changed the title Treat 403 errors differently when due to lack of API support Treat 403 errors differently when due to lack of API support or API request limit exceeded Mar 17, 2017
@ghost
Copy link

ghost commented Mar 17, 2017 via email

@mike4aday
Copy link
Owner Author

@pbrondum I'll include the changes in the next release. BTW Salesforce does return API limit info with every response, in the header (below), though Swiftly Salesforce doesn't currently do anything with it.

If I found a useful way to surface the current state of API usage, would you code for it and take different action - or you'd just prefer to know after the limit was exceeded and tell the user to wait a while?

Example of HTTP response header:
Sforce-Limit-Info: api-usage=18/5000

@mike4aday mike4aday added bug and removed enhancement labels Mar 17, 2017
mike4aday pushed a commit that referenced this issue Jun 7, 2017
@mike4aday
Copy link
Owner Author

Fixed in release version 3.5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant