UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

28 lines (25 loc) 1.07 kB
const { getMessage } = require('./logging'); function handleHttpError(error, params, { url, command } = {}) { url = url ?? params.get('appUrl'); const prefix = `Request to ${url} failed`; switch (error.status) { case 401: throw getMessage(`${prefix}: invalid authentication` + ( params.has('username') ? `. Ensure that username and password are correct` : '' ), { error, command }); case 403: throw getMessage(prefix + ': insufficient authorization. Ensure the user has all necessary roles.', { error, command }); case 404: throw getMessage(prefix + ': resource not found.', { error, command }); case 422: // Compilation or native-extension error. throw getMessage(prefix + '.', { error, command }); default: // Unexpected error should be transparent to user. delete error.status; // Purge extra property already included in message. throw error; } } module.exports = { handleHttpError };