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.
There are a small handful of error handling issues we have run into that I keep meaning to put into a pull request. But I think I may need a bit of guidance on how you prefer to manage exceptions. This draft starts with one of the issues we've run into.
Description
A super admin gets an error message when trying to add or modify a page for book where they are not an author:
For us, this happens most often when we are working with an author and demonstrating a feature.
Issue
bc2b134
It looks as if error is expecting a message but is being passed a XMLHttpRequest object. Elsewhere I see you access the error message using the responseJSON method when presented with a similar situation, and that is what I've done here.
I think there are other error messages that follow this same pattern (e.g., attempt to print a XMLHttpRequest object)--is this the fix you'd like to see?
871e7c8
The other issue is with the logic of this exception. It seems like super admins, who could add themselves to the book's users, should be able to make changes to any book. So, the second commit changes the exception logic to display the error only if the user is not a book author and is not a super admin.
But let me know if this is an intentional move to provide a method that prevents super admins from accidentally making changes.