-
-
Notifications
You must be signed in to change notification settings - Fork 839
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
Some improvements to request error handling and modal error formatting #1929
Conversation
Won't closing the currently active Modal cause unwanted side effects? I can imagine this would happen on log in, register etc; even so.. can't we make the error be pushed on top of the overlay somehow? Ps, I also assume that changing these outputs will break all extensions returning custom error output? |
Perhaps. The problem isn't the error alert being behind the modal, is that showing the alert results in the modal fade out animation to trigger, but the backdrop remains. Might be a separate issue though.
I don't understand what you are saying here. The |
Ah your answer clarifies it. Then I have nothing to add ;) |
Asked for second review from @clarkwinkelmann ; if approved feel free to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great, but I have some concerns:
Why use unescape()
which is deprecated ? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape . Why is a decoding necessary at all ?
What is the purpose of the new this.modal.close()
? It sounds like if any error is triggered while a modal is open and the request isn't bound to that modal handler, it would close it, potentially losing data. I think core always uses the error handling inside the modal, but extension might do their own requests from the modal.
I wanted to test this with fof/terms for example. It means an error fetching the list of policies, reordering, or during saving would close the modal. But I couldn't test because of the issue I discussed on Discord where I can't install terms on my master Flarum 🤷♂️
@clarkwinkelmann Escape is required to transform I changed the function call to |
Those are great cases for inline comments I think 😄 If newlines are the only reason to use it, wouldn't If we keep it like it's now I suggest adding
as a comment near Otherwise approved 👍 |
js/src/common/Application.js
Outdated
|
||
error.alert = new Alert({ | ||
type: 'error', | ||
children, | ||
controls: isDebug && [ | ||
<Button className="Button Button--link" onclick={this.showDebug.bind(this, error)}>Debug</Button> | ||
<Button className="Button Button--link" onclick={this.showDebug.bind(this, error, formattedError)}>Debug</Button> | ||
] | ||
}); | ||
|
||
try { | ||
options.errorHandler(error); | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah, can we rename this error
variable in the catch
block? I find it super confusing to follow along which object we're dealing with here. 😁
🕐 Three minutes later...
Okay, I see now, the default errorHandler
implementation just re-throws the same object, which means we have an AJAX error, which makes sense.
Could we change this to check for the existence of options.errorHandler()
instead? The try
/catch
only confuses the reader IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Had to remove the default errorHandler
implementationa as it's not needed.
I noticed that when the error handler is set - e.g. modals using this.onerror
- nothing logs to the console. I assume we want to log the error to the console regardless if the error handler is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, no, I think we should reserve the logging to unexpected errors - exactly the way you did it.
Really, it depends on whether we're dealing with a known or unknown error, but we have no mechanism for that yet (in custom error handlers).
b5e5918
to
861d598
Compare
I have still not had time to test this locally, but from reading the code: Aren't we losing the feature of the I'm actually using this feature in my Formulaire extension. If the errors are not validation errors for my fields, I re-throw the error, making Flarum render it in the error alert. This PR appears to remove that feature. Now if I suppose any custom |
Would it make sense to log all errors to console, even if We're already going to log most validation errors to the console with the current implementation I believe. We might as well log all request errors. This would also simplify re-implementing the feature I said was removed in my previous comment as the conditions can be moved up in the code. EDIT: I see this was discussed 10 days ago in one of the comment discussions above. If we don't want to log handled errors, maybe we should not log validation errors either ? This is kind of their expected handling if nothing more specific was defined 🤔 |
You make a good point. I guess there's no reason not to log e.g. validation errors - it can make debugging easier even when it's just a handled error. The catching of |
Because we now auto-format our JS code with Prettier, this branch now has conflicts with Please take the steps outlined in the forum to resolve the conflicts. |
* Use decodeURI instead of unescape & don't close modals * Add comment * Don't use a try/catch, clean up the group log code * Remove double negative * Format; fix issues from rebasing
fdba98d
to
fb43e5f
Compare
I rebased & squashed as I realized I hadn't done it correctly. I also restored the |
Still looking good to me |
This doesn't clash with any of the state changes afaik, and we might as well put it in now instead of after TS when more work will be needed to get it updated. As 3 core devs have approved and there seems to be no conflicts, merging. |
Changes proposed in this pull request:
Reviewers should focus on:
The alert appearing was causing the modal to "close" but the background overlay remained... not sure if that's a bug or intended (?) so I closed the currently opened modal - though I don't think want to do that.
Screenshot
POST /api/flags 404
POST /flags 404
Confirmed
Backend changes: tests are green (runcomposer test
).