# all files / errors/ error-handler.js

100% Statements 13/13
100% Branches 10/10
100% Functions 2/2
100% Lines 5/5
1 branch Ignored

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    1
    6
    6
    6

     'use strict';

    // Constants:
    import constants from '../constants';

    // Utilities:
    import log from 'npmlog';

    export default { handler };

    function handler (response, error, message) {
        log.error(message || error.message);
        response.status(error.status || constants.SERVER_ERROR);
        response.send(JSON.stringify({
            error: message || error.message
        }));
    }