-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(feedback): updated response feedback quality (closes #30)
- Loading branch information
1 parent
22a77de
commit 8c4404c
Showing
5 changed files
with
83 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export interface MicroserviceErrorOptions { | ||
error: string; | ||
code?: number; | ||
success?: boolean; | ||
info?: object | null; | ||
data?: object | null; | ||
} | ||
|
||
export class MicroserviceError extends Error { | ||
json: MicroserviceErrorOptions; | ||
|
||
constructor(options: MicroserviceErrorOptions) { | ||
super(options.error); | ||
this.name = 'MicroserviceError'; | ||
this.json = options; | ||
this.json.code = typeof options.code === 'number' ? options.code : 500; // Default to Internal Server Error if no status code is provided | ||
this.json.success = options?.success ? options.success : false; // so that you can always check the response status, even if it's an error | ||
this.json.info = options?.info ? options.info : null; | ||
this.json.data = options?.data ? options.data : null; // so that you can always check the response data, even if it's an error | ||
|
||
// Capturing stack trace, excluding constructor call from it. | ||
if (typeof Error.captureStackTrace === 'function') { | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
|
||
toJSON(): MicroserviceErrorOptions { | ||
return JSON.parse(JSON.stringify(this.json)); // so that functions and so on are being converted to json | ||
} | ||
|
||
toString(): string { | ||
return JSON.stringify(this.json); | ||
} | ||
} |
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
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