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

Use DOMException instead of Error #38

Open
dsanders11 opened this issue Dec 19, 2018 · 3 comments
Open

Use DOMException instead of Error #38

dsanders11 opened this issue Dec 19, 2018 · 3 comments

Comments

@dsanders11
Copy link
Contributor

For the errors listed in the spec (InvalidStateError, NotFoundError, etc), these should be DOMExceptions with the name set accordingly.

Example:

throw new DOMException('interface not found', 'NotFoundError');

To make it cleaner to implement in the code, may consider using a helper class for each error:

class NotFoundError {
    constructor(message) {
        return new DOMException(message, 'NotFoundError');
    }
}
@thegecko
Copy link
Owner

Hmm, I believe DOMException is unique to browser environments. Not sure it makes sense to use it in other runtimes such as node.

@dsanders11
Copy link
Contributor Author

@thegecko, you're right. 🙂 My use-case for this library at the moment is in Electron, as they don't currently support native WebUSB due to issues with the browser UI needing to ask permission before accessing devices. As such I'd like my code to be as API-compatible as possible so I can (in theory) seamlessly switch between the two.

What about at least an error which emulates the shape of DOMException? Namely that it would have a name property? That seems to be the only real difference between a normal Error, and would allow code which checks the name of the error to work with both this library, and a browser implementation.

@thegecko
Copy link
Owner

I'm happy with that approach, recommend we create an interface to match DOMException for this purpose. I'll think about a name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants