Skip to content

Commit

Permalink
custom error in graphql server
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuaste committed Feb 19, 2019
1 parent 81f8d9f commit 9144f7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ app.use('/login', cors(), (req, res)=>{
context: {
request: req,
acl: acl
},
formatError(error){
return {
message: error.message,
details: error.originalError.errors,
path: error.path
};
}
})));

Expand Down
26 changes: 26 additions & 0 deletions utils/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

class customArrayError extends Error {
constructor(errors_array, message){
super();
this.message = message;
this.errors = errors_array;
}
}

class otherError extends Error {
constructor(oneError,message){
super();
this.message = message;
this.detail = oneError;
}
}

handleError = function(error){
if(error.name === "SequelizeValidationError"){
throw new customArrayError(error.errors, "Validation error");
}else{
throw new Error(error)
}
}

module.exports = { handleError}

0 comments on commit 9144f7e

Please sign in to comment.