UNPKG

mares-error-mapper

Version:

마레스 에러를 번역 및 매핑하는 모듈입니다.

49 lines (44 loc) 1.31 kB
const _ = require('lodash') const utils = require('./utils') module.exports.uniqueMapper = (excludingParams) => { return (req, res, next) => { let result = req.result if (result && result.status === 409 && result.body && result.body.rows) { let rows = result.body.rows let newRows = utils.excludeErrorObject(rows, excludingParams) result.body.rows = newRows if (result.body.count) result.body.count = newRows.length } next() } } module.exports.codeTranslator = (codeLang) => { return (req, res, next) => { let result = req.result if (result && result.status >= 400) { let rows = result.body.rows let newRows = utils.translateErrorCode(rows, codeLang) result.body.rows = newRows } next() } } module.exports.codeTranslatorByJson = (codeLangJson) => { return (req, res, next) => { let result = req.result if (result && result.status >= 400) { let rows = result.body.rows let newRows = utils.translateErrorCodeByJson(rows, codeLangJson) result.body.rows = newRows } next() } } module.exports.translateCode = (rows, codeLang) => { let newRows = utils.translateErrorCode(rows, codeLang) return newRows } module.exports.translateCodeByJson = (rows, codeLangJson) => { let newRows = utils.translateErrorCodeByJson(rows, codeLang) return newRows }