Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling, logging, and request validation #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ const options = {
const express = require('express'),
bodyParser = require('body-parser'),
app = express();
const morgan = require('morgan');
const { check, validationResult } = require('express-validator');

app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Middleware to handle validation errors
const validateRequest = [
check('transactionID').notEmpty().withMessage('transactionID is required'),
check('amount').isNumeric().withMessage('amount must be a number'),
(req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
next();
}
];

/*
B2C ResultURL
URL: /b2c/result
Expand Down