UNPKG

feathers-http-distributed

Version:

Distribute FeathersJS apps over the network with inter-service communication using HTTP protocol

31 lines (24 loc) 766 B
const errors = require('@feathersjs/errors'); const { convert } = require('@feathersjs/errors'); const errorHandler = function (error) { const err = error.response ? error.response.data || error.response : error; let feathersError; if (error.response) { if (err.status === 404) { feathersError = new errors.NotFound(err); } } else if (err.code) { if (err.code === 'ECONNABORTED') { feathersError = new errors.FeathersError(err, 'GatewayTimeout', 504, 'gateway-timeout'); } } else { feathersError = new errors.BadGateway(err); } if (!feathersError) { feathersError = convert(err); } delete feathersError.isAxiosError; delete feathersError.config; return feathersError; }; module.exports = errorHandler;