BerniWittmann/spielplanismaning

View on GitHub
src/routes/messages/ErrorMessage.js

Summary

Maintainability
A
0 mins
Test Coverage
const _ = require('lodash');

module.exports = function (err) {
    /**
     * @apiDefine ErrorMessage
     *
     * @apiError (Error) {String} MESSAGE Error-Message: 'Error'
     * @apiError (Error) {Integer} STATUSCODE Status-Code: 200
     * @apiError (Error) {String} MESSAGEKEY Key der Message: 'ERROR_MESSAGE'
     * @apiError (Error) {Object} ERROR Error Object
     *
     * @apiErrorExample Error-Response Error:
     *     HTTP/1.1 500 INTERNAL SERVER ERROR
     *     {
     *          "MESSAGE": "Error",
     *          "STATUSCODE": 500,
     *          "MESSAGEKEY": "ERROR_MESSAGE",
     *          "ERROR": [ Object ]
     *     }
     */
    return {
        MESSAGE: 'Error',
        STATUSCODE: 500,
        MESSAGEKEY: 'ERROR',
        ERROR: _.isUndefined(err) || _.isUndefined(err.message) ? err : err.message
    };
};