Skip to content

Commit

Permalink
Merge pull request #180 from hyeeyoung/dev
Browse files Browse the repository at this point in the history
release 1.0.2
  • Loading branch information
hyejungg authored Apr 6, 2022
2 parents 8f6abbf + 851a41e commit ee05320
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/middleware/handleError.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const { GeneralError } = require('../utils/errors');
const { ErrorMessage } = require('../utils/response');
const logger = require('../config/winston');
const Slack = require('../lib/slack');

const handleErrors = (err, req, res, next) => {
logger.error(err);
if (err instanceof GeneralError) {
Slack.sendMessage({
color: Slack.Colors.info,
title: `${err.getCode()} ${err.message}`,
text: `[${req.method}] ${req.url} \`\`\`user-agent: ${req.header(
'user-agent',
)} \nip-adress: ${req.ip}\`\`\``,
});
if (
err.message === ErrorMessage.BadRequestMeg ||
err.message === ErrorMessage.ApiUrlIsInvalid
) {
Slack.sendMessage({
color: Slack.Colors.info,
title: `${err.getCode()} ${err.message}`,
text: `[${req.method}] ${req.url} \`\`\`user-agent: ${req.header(
'user-agent',
)} \nip-adress: ${req.ip}\`\`\``,
});
}
return res.status(err.getCode()).json({
success: false,
message: err.message,
Expand Down

0 comments on commit ee05320

Please sign in to comment.