@soleil-se/run
Version:
Run various utility scripts for creating apps, configs or migration tasks.
24 lines (21 loc) • 885 B
JavaScript
import { HTTPError } from 'got';
function handleError(error) {
if (error instanceof HTTPError) {
const { response } = error;
if (response.statusCode === 401) {
throw new Error(`${error.name}: ${response.statusCode} - Unauthorized, correct username and password?`);
}
if (response.statusCode === 500) {
if (response.body instanceof Buffer) {
const { message } = JSON.parse(response.body.toString());
throw new Error(`${error.name}: ${response.statusCode} - ${message}`);
}
throw new Error(`${error.name}: ${response.statusCode} - Would write some kind of proper error message if SiteVision told us what went wrong...`);
}
}
if (error.message === 'URI malformed') {
throw new Error('URI malformed - Username or password may contain special characters?');
}
throw new Error(error);
}
export default handleError;