Removed circular dependencies between APIs and CMI objects
No longer directly setting error codes on the API when a read/write or data validation fails, throwing exceptions instead that can then be caught by the APi.
This commit is contained in:
33
src/exceptions.js
Normal file
33
src/exceptions.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// @flow
|
||||
|
||||
/**
|
||||
* Data Validation Exception
|
||||
*/
|
||||
export class ValidationError extends Error {
|
||||
/**
|
||||
* Constructor to take in an error message and code
|
||||
* @param {number} errorCode
|
||||
*/
|
||||
constructor(errorCode: number) {
|
||||
super(errorCode);
|
||||
this.#errorCode = errorCode;
|
||||
}
|
||||
|
||||
#errorCode;
|
||||
|
||||
/**
|
||||
* Getter for #errorCode
|
||||
* @return {number}
|
||||
*/
|
||||
get errorCode() {
|
||||
return this.#errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to override the default Error message
|
||||
* @return {string}
|
||||
*/
|
||||
get message() {
|
||||
return this.#errorCode + '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user