Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs mysql error handling with user example

catch (err) {
  if (err instanceof Errors.BadRequest)
    return res.status(HttpStatus.BAD_REQUEST).send({ message: err.message }); // 400
  if (err instanceof Errors.Forbidden)
    return res.status(HttpStatus.FORBIDDEN).send({ message: err.message }); // 403
  if (err instanceof Errors.NotFound)
    return res.status(HttpStatus.NOT_FOUND).send({ message: err.message }); // 404
  if (err instanceof Errors.UnprocessableEntity)
    return res.status(HttpStatus.UNPROCESSABLE_ENTITY).send({ message: err.message }); // 422
  console.log(err);
  return res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({ error: err, message: err.message });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if class is clicked javascript 
Javascript :: vue mixin example 
Javascript :: res.write in node js 
Javascript :: nohup nodemon 
Javascript :: react function runs several times 
Javascript :: js add props to obj conditionally 
Javascript :: fs renameSync 
Javascript :: react useeffect on change props 
Javascript :: shopify api for add to cart 
Javascript :: js variable for key obj 
Javascript :: rating calculator formula javascript 
Javascript :: nestjs AXIOS_INSTANCE_TOKEN 
Javascript :: reactt split a value and sepate 
Javascript :: deserialize json to c# object 
Javascript :: Google App Script getSheetByName 
Javascript :: create own rules jquery 
Javascript :: java script append element to array 
Javascript :: regex contains special characters javascript 
Javascript :: javascript sleep 1 minute 
Javascript :: add new array at the back of react state 
Javascript :: convertir lista a Json en Java 
Javascript :: leaflet 
Javascript :: jquery has class 
Javascript :: express-jwt 
Javascript :: bind json data to dropdownlist using javascript 
Javascript :: javascript object properties 
Javascript :: how to edit a fil with vanilla js 
Javascript :: jquery scroll to element toggle menu item 
Javascript :: JavaScript Checking in switch Statement 
Javascript :: exponential javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =