feat: Convert ts files to js files for errors directory

This commit is contained in:
Faruk AYDIN
2023-12-28 13:14:58 +01:00
parent a2986d70a0
commit 9b01a2a4da
8 changed files with 30 additions and 41 deletions

View File

@@ -0,0 +1,33 @@
export default class BaseError extends Error {
details = {};
constructor(error) {
let computedError;
try {
computedError = JSON.parse(error);
} catch {
computedError =
typeof error === 'string' || Array.isArray(error) ? { error } : error;
}
let computedMessage;
try {
// challenge to input to see if it is stringified JSON
JSON.parse(error);
computedMessage = error;
} catch {
if (typeof error === 'string') {
computedMessage = error;
} else {
computedMessage = JSON.stringify(error, null, 2);
}
}
super(computedMessage);
this.details = computedError;
this.name = this.constructor.name;
}
}