-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added better error handling which fixed #91
- Loading branch information
Showing
4 changed files
with
92 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*eslint no-console: 0 */ | ||
|
||
class ErrorHandler{ | ||
constructor(api){ | ||
this.api = api; | ||
} | ||
|
||
handleCatch(e){ | ||
// If babel supported extending of Error in a correct way instanceof would be used here | ||
if(e.name === "InvalidInputException"){ | ||
if(this.api._options.valid !== this.api._defaults.valid){ | ||
this.api._options.valid(false); | ||
} | ||
else{ | ||
throw e.message; | ||
} | ||
} | ||
else{ | ||
throw e; | ||
} | ||
|
||
this.api.render = function(){}; | ||
} | ||
|
||
wrapBarcodeCall(func){ | ||
try{ | ||
var result = func(...arguments); | ||
this.api._options.valid(true); | ||
return result; | ||
} | ||
catch(e){ | ||
this.handleCatch(e); | ||
|
||
return this.api; | ||
} | ||
} | ||
} | ||
|
||
export default ErrorHandler; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class InvalidInputException extends Error{ | ||
constructor(symbology, input) { | ||
super(); | ||
this.name = "InvalidInputException"; | ||
|
||
this.symbology = symbology; | ||
this.input = input; | ||
|
||
this.message = '"' + this.input + '" is not a valid input for ' + this.symbology; | ||
} | ||
} | ||
|
||
class InvalidElementException extends Error{ | ||
constructor() { | ||
super(); | ||
this.name = "InvalidElementException"; | ||
this.message = "Not supported type to render on"; | ||
} | ||
} | ||
|
||
class NoElementException extends Error{ | ||
constructor() { | ||
super(); | ||
this.name = "NoElementException"; | ||
this.message = "No element to render on."; | ||
} | ||
} | ||
|
||
export {InvalidInputException, InvalidElementException, NoElementException}; |
This file contains 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