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
PushRegisterMessage => PushError #18
Comments
Can we phrase this so that it inherits from DOMException? The reason afaik should be a string. The type could be RegistrationMissingError or OutOfSyncError. I'm not sure what the formal pattern looks like exactly. |
I think the enum approach would look as follows in WebIDL: [Constructor(DOMString type, optional PushErrorEventInit eventInitDict), Exposed=ServiceWorker]
interface PushErrorEvent : Event {
readonly attribute PushErrorReason reason;
};
dictionary PushErrorEventInit : EventInit {
PushErrorReason reason;
};
enum PushErrorReason {
"registration-missing",
"out-of-sync"
}; So the javascript would then look like: this.onerror = function(event) {
switch(event.reason) {
case "registration-missing":
...
break;
case "out-of-sync":
...
break;
}
}; |
The enum approach has a drawback: it is basically reinventing [Constructor(DOMString type, optional PushErrorEventInit eventInitDict), Exposed=ServiceWorker]
interface PushErrorEvent : Event {
readonly attribute DOMException error;
};
dictionary PushErrorEventInit : EventInit {
DOMException error;
}; We can then add So the javascript would then look like: this.onerror = function(event) {
switch(event.error.name) {
case "PushRegistrationLost":
...
break;
case "PushOutOfSync":
...
break;
}
}; I think the DOMException approach has two drawbacks of its own:
|
Maybe this can reuse http://www.whatwg.org/specs/web-apps/current-work/#the-errorevent-interface in some way? |
Isn't
|
I think it would be nice to have a |
@mvano I would expect |
@annevk So the switch would be on |
@annevk, ErrorEvent seems to be for js runtime errors with the line/column numbers. Why re-use that. Though, we could make this inherit from a base class. |
ErrorEvent seems fine if the intent here is to wrap up an exception. Most exceptions generated by the DOM (including most DOMExceptions) do not have a line/column number. I imagine I can put together a quick test case to show that. Is the goal to wrap up an exception, though? E.g. does this exception show up elsewhere as a promise rejection or thrown exception? |
No this is not an exception that might be thrown or used to reject a promise. This is an event indicating that e.g. the client is out of sync with the server, or the registration has been invalidated and must be renewed. Still it looks exactly like an exception: it needs a type or a name, and it would be nice to provide a message field for the author as well. If I was to invent a clean new generic type it would look like this: interface ErrorEvent : Event {
readonly attribute DOMString name;
readonly attribute DOMString message;
}; |
Why not using DOMExceptions instead of having |
@mounirlamouri, because we're firing an event, not throwing an error that can be caught or is used to reject a promise. The Anyway, that's my ideal, the cleanest, most generic form of an event that signals some kind of error happened. I can use less pretty syntax if it avoids reinventing multiple wheels. |
@mvano if you actually expect people to branch based on the error, why not have distinct events? |
@mvano that seems much more natural for an event based system. You could even dispatch the specific event first and then a generic simple event named error. Various APIs have such a setup. |
@annevk That's an interesting idea, thanks. Just firing distinct simple events of type |
👍 |
Please keep the names all lowercase, but yes. |
PushRegisterMessage => PushError with 'reason' attribute (enumeration). Now it covers at least 2 type of errors:
1- new registration is needed (e.g. due to fatal error at server),
2- "out of sync" , informational and does not imply registration has ended
The text was updated successfully, but these errors were encountered: