Codebase list node-err-code / 77af86df-6f58-43b8-a48d-87c070ef62c1/main index.js
77af86df-6f58-43b8-a48d-87c070ef62c1/main

Tree @77af86df-6f58-43b8-a48d-87c070ef62c1/main (Download .tar.gz)

index.js @77af86df-6f58-43b8-a48d-87c070ef62c1/mainraw · history · blame

'use strict';

function createError(err, code, props) {
    var key;

    if (!(err instanceof Error)) {
        throw new TypeError('Please pass an Error to err-code');
    }

    if (typeof code === 'object') {
        props = code;
    } else if (code != null) {
        err.code = code;
    }

    if (props) {
        for (key in props) {
            err[key] = props[key];
        }
    }

    return err;
}

module.exports = createError;