-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
blockchain_integration/pi_network/cognita/kyc/utils/error-handler.js
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 @@ | ||
const { ErrorTypes } = require('./error-types'); | ||
|
||
class ErrorHandler { | ||
static handle(error) { | ||
if (error instanceof Error) { | ||
console.error(`Error: ${error.message}`); | ||
console.error(`Stack: ${error.stack}`); | ||
} else { | ||
console.error(`Unknown error: ${error}`); | ||
} | ||
|
||
switch (error.code) { | ||
case ErrorTypes.INVALID_REQUEST: | ||
return { statusCode: 400, message: 'Invalid request' }; | ||
case ErrorTypes.UNAUTHORIZED: | ||
return { statusCode: 401, message: 'Unauthorized' }; | ||
case ErrorTypes.FORBIDDEN: | ||
return { statusCode: 403, message: 'Forbidden' }; | ||
case ErrorTypes.NOT_FOUND: | ||
return { statusCode: 404, message: 'Not found' }; | ||
case ErrorTypes.INTERNAL_SERVER_ERROR: | ||
return { statusCode: 500, message: 'Internal server error' }; | ||
default: | ||
return { statusCode: 500, message: 'Unknown error' }; | ||
} | ||
} | ||
} | ||
|
||
module.exports = ErrorHandler; |