-
-
Save spion/51bc9b9a3247bbfa0fda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class CodedError extends Error { | |
constructor(code, msg) { | |
super(msg) | |
this.code = code; | |
this.msg = msg; | |
} | |
static is(code) { | |
return (e) => e.code == code; | |
} | |
static only(code, handler) { | |
return err => { | |
if (err.code === code) return handler(err) | |
throw err; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment