Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was brought to my attention on Discord that a61aa7e broke error handling in PPM.
The clue to find out what had gone wrong was the fact that the unstar command still worked.
This is because in that PR I had told
superagent
a list of status codes to not error on. This means that when we got, say a 404, the actualerror
object returned to the callback would benull
even though those commands then relied on theerror
object to determine what had gone wrong.So what I've done, is provide both the
error
andbody
to therequest.getErrorMessage()
so that we can check for errors in either of them.Meaning when a request fails we will:
superagent
error object forerr.response.body
then forerr.response.error
then forerr
body.message
thenbody.error
then finallybody
This helpfully means we prioritize any errors returned by
superagent
then any errors returned by the backend. And if all else fails, we just tell the user whatever message was returned to us by the backend, which can be helpful in case the backend's error schema ever changes by accident or on purpose and isn't updated here. So that way we can always inform the user exactly what the backend is thinking.