Raise a specific exception if response from API is HTTP 401#9
Conversation
| # Q: Shouldn't we also raise for 4xx errors? | ||
| # A: We let TypedErrorMiddleware handle those, in case they have useful info. |
There was a problem hiding this comment.
Is this comment still relevant?
There was a problem hiding this comment.
Hmm I'm not sure. From the comment it seems that we thought that 4xx errors would include additional information about the error in the body. In the case of 401 errors the XML returned from the service is:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<status>401</status>
<error>Unauthorized</error>
<message>You have attempted to access a restricted resource</message>
</response>
So we probably only care about errors with code 400 for TypedErrorMiddleware. MobileCommons' API docs (https://faq.mobilecommons.com/hc/en-us/articles/38902578710811-Mobile-Commons-Rest-API#errors) are completely broken, so I don't know which status code is sent for each of the specific errors we've handling for on https://github.com/controlshift/upland_mobile_commons_rest/blob/main/lib/upland_mobile_commons_rest/errors.rb#L140, so"ll just update the comment to reflect this small change without making any other updates just in case.
6d85e44 to
ac0984e
Compare
Raise an
UnauthorizedErrorerror if the service's response status code is 401.