Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const transformError = (err: Error & { statusCode?: number }) => {
if (Boom.isBoom(err)) {
return err;
} else {
if (err.statusCode != null) {
return new Boom(err.message, { statusCode: err.statusCode });
} else if (err instanceof TypeError) {
// allows us to throw type errors instead of booms in some conditions
// where we don't want to mingle Boom with the rest of the code
return new Boom(err.message, { statusCode: 400 });
} else {
// natively return the err and allow the regular framework
// to deal with the error when it is a non Boom
return err;
}
}
};
});
if (count === 0) {
sampleDataset.status = NOT_INSTALLED;
return;
}
} catch (err) {
sampleDataset.status = UNKNOWN;
sampleDataset.statusMsg = err.message;
return;
}
}
try {
await context.core.savedObjects.client.get('dashboard', sampleDataset.overviewDashboard);
} catch (err) {
// savedObjectClient.get() throws an boom error when object is not found.
if (isBoom(err) && err.output.statusCode === 404) {
sampleDataset.status = NOT_INSTALLED;
return;
}
sampleDataset.status = UNKNOWN;
sampleDataset.statusMsg = err.message;
return;
}
sampleDataset.status = INSTALLED;
});
}).catch(function(error) {
let reject = boom.isBoom(error) && [401, 500].includes(error.output.statusCode)
if (!reject && config.retries > 0) {
config.retries--
if (!config.silent && process.env.DEVELOPMENT && process.env.SERVER) {
console.warn('retry Error ->', config, error)
}
if (process.env.CLIENT) global.cookies();
return clock.toPromise(config.retryTick).then(() => send(config))
}
return Promise.reject(error)
})
}
.use(async (ctx, next) => {
try {
await next();
if ((ctx.status === 404) || (ctx.body === undefined)) {
ctx.body = { statusCode: 404, error: 'Not Found',
message: 'Resource not found.' };
ctx.status = 404;
}
} catch (err) {
if (Boom.isBoom(err)) {
ctx.response.headers = err.output.headers;
ctx.body = err.output.payload;
ctx.status = err.output.statusCode;
} else {
ctx.status = 500;
ctx.body = { statusCode: ctx.status, error: 'Internal Server Error',
message: err.message };
}
console.error(err.stack);
}
})
.use(jobCatcher)
operations.forEach(({ operation, args }) => {
try {
sharp = operation.handler(this, sharp, ...args)
} catch (e) {
if (Boom.isBoom(e)) {
throw e
}
console.error(e + '')
throw Boom.internal()
}
})
const data = await sharp.toBuffer()
const errorMessages: Array = (errors || []).map(error => {
if (Boom.isBoom(error as any)) {
return (error as Boom).output.payload as Payload;
}
return error as SavedObjectsImportError;
});
return async (
context: RequestHandlerContext,
request: KibanaRequest,
response: KibanaResponseFactory
) => {
try {
return await handler(context, request, response);
} catch (e) {
if (Boom.isBoom(e)) {
return response.customError({
body: e.output.payload,
statusCode: e.output.statusCode,
headers: e.output.headers,
});
}
throw e;
}
};
};
export function getErrorStatusCode(error: any): number {
return Boom.isBoom(error) ? error.output.statusCode : error.statusCode || error.status;
}
export function wrapError(error: any) {
if (isBoom(error)) {
return error;
}
return boomify(error, { statusCode: error.status });
}
handler: async (req: Request) => {
const { context, params } = req.payload as RequestPayload;
this.log.debug(`Receiving RPC call ${req.url.path} ${util.inspect(params)}`);
const endpoint: Endpoint = {
toContext(): RequestContext {
return context;
},
};
try {
const data = await serviceMethodMap[method](endpoint, params);
return { data };
} catch (e) {
if (!Boom.isBoom(e)) {
throw Boom.boomify(e, { statusCode: 500 });
} else {
throw e;
}
}
},
});