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

More error handling in the polling client #43

Merged
merged 7 commits into from
Aug 26, 2020

Conversation

OmarWKH
Copy link
Collaborator

@OmarWKH OmarWKH commented Aug 23, 2020

This adds more specific error handlers. As a result:

  1. Package users can better customize error handling.
  2. The polling client can detect more errors.

onError becomes the default generic handlers. Users can customize task errors, network errors, HTTP errors, and data errors. I describe each of them in the README.

I also replaced if (data.result) with if (data.hasOwnProperty('result')). The former fails if result is false and assumes there is no result.

I tested these use cases:

  1. Network error (offline).
  2. Server returns non-200 response (I need this because I wrap celery-progress's view with my own that does authorization).
  3. Server returns 200 response with non-JSON data.
  4. Server returns 200 response with invalid JSON data (it doesn't have data.complete or data.success).
  5. Successful task.
  6. Failed task.
  7. Task with result.

3 and 4 are programming errors handled by onDataError. There's no good way to handle them except show the user an error and stop polling.

This could address #13.

This is only for the polling client. I do not use webosckets currently, so I can't test websocket specific errors.

Copy link
Owner

@czue czue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Give me a few days to do a bit of testing and I'd also be interested to hear from @EJH2 on the websockets bit (though looks innocuous enough).

response = await fetch(progressUrl);
} catch (networkError) {
onNetworkError(progressBarElement, progressBarMessageElement, "Network Error");
throw networkError;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the value in re-throwing this one (and the parsingError)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Show a helpful exception in the browser console.
  2. Stop executing the rest of the function.

This is the console if I throw networkError:
throwNetwork

If I don't throw networkError:
noThrowNetwork

If I throw parsingError:
throwParsing

If I don't throw parsingError:
noThrowParsing

If we don't want to throw, we could either:

  • check that response and data are defined before using them
  • or return
  • or use .then/.catch callbacks instead of try/catch
  • or move the "success" code inside the try block

function onErrorDefault(progressBarElement, progressBarMessageElement, excMessage) {
CeleryProgressBar.onErrorDefault(progressBarElement, progressBarMessageElement, excMessage);
function onErrorDefault(progressBarElement, progressBarMessageElement, excMessage, data) {
CeleryProgressBar.onErrorDefault(progressBarElement, progressBarMessageElement, excMessage, data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EJH2 do you have any thoughts on this part? I also have never used the websockets client.

@@ -22,7 +26,7 @@ var CeleryProgressBar = (function () {
progressBarMessageElement.innerHTML = progress.current + ' of ' + progress.total + ' processed. ' + description;
}

function updateProgress (progressUrl, options) {
async function updateProgress (progressUrl, options) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for updating this

@OmarWKH
Copy link
Collaborator Author

OmarWKH commented Aug 23, 2020

I found celery-progress really helpful so I'm happy to contribute. Thanks for making it :)

@EJH2
Copy link
Collaborator

EJH2 commented Aug 23, 2020

Hey there, I'd be happy to look at this with the websocket implementation in a day or two. I don't expect to see any issues because the websocket functions pretty much the same as http, but I'll make sure to let you know if I find anything!

@czue
Copy link
Owner

czue commented Aug 26, 2020

@EJH2 I'm going to merge this for now though feel free to leave any comments if there are any issues. I'll plan to cut a new release in the next few days.

@czue czue merged commit 28ce62a into czue:master Aug 26, 2020
@EJH2
Copy link
Collaborator

EJH2 commented Aug 27, 2020

Everything looks fine to me on the websocket side of things!

@czue
Copy link
Owner

czue commented Aug 27, 2020

Just released this in 0.11. thanks for the contribution!

@OmarWKH OmarWKH deleted the error-handling-polling branch August 31, 2020 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants