Skip to content

Commit

Permalink
BE #1: Add middleware to send if there is any json parsing error happ…
Browse files Browse the repository at this point in the history
…ens.
  • Loading branch information
Atiqul Alam Rocky committed May 12, 2020
1 parent 6d8d0dc commit 4bfc417
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const express = require('express');
const logger = require('morgan');
const morgan = require('morgan');
const fs = require('fs')
const { connect } = require('mongoose')
const {success, error, info, log} = require('consola');
Expand All @@ -10,6 +10,23 @@ const {DB, PORT} = require('./config/application');
//Initialize the application
const app = express();

//Middleware
app.use(morgan('tiny'));
app.use(express.json());
app.use(function (err, req, res, next) {
if (err instanceof SyntaxError) {
error({message:err, badge:true})
return res.status(400).json({message:err.message})
}else{
next();
}

});


//Router middleware
app.use('/api/user', require('./routes/users'));

let retryAttemptCount = 5;
const startApp = async function(){
try{
Expand Down

0 comments on commit 4bfc417

Please sign in to comment.