refactor validation error and general error handling to reduce code duplicatoin
This commit is contained in:
1 parent
bc001c6a0e
commit
8578304ca4
9 files changed
+446
-600
No files matched your search
@@ -0,0 +1,19 @@
|
||||
const handleValidationError = (error, serviceName) => {
|
||||
error.status = 422;
|
||||
error.service = serviceName;
|
||||
error.message =
|
||||
error.details?.[0]?.message || error.message || "Validation Error";
|
||||
return error;
|
||||
};
|
||||
|
||||
const handleError = (error, serviceName, method, code = 500) => {
|
||||
error.code === undefined ? (error.code = code) : null;
|
||||
error.service === undefined ? (error.service = serviceName) : null;
|
||||
error.method === undefined ? (error.method = method) : null;
|
||||
return error;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
handleValidationError,
|
||||
handleError,
|
||||
};
|
||||
Reference in new issue
Block a user