Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function promiseTimeout(ms: number, promise: Promise): Promise {
const boom = Boom.gatewayTimeout('Timed out in ' + ms + 'ms.');
// @ts-ignore
boom.isTimeout = true;
if (ms > 0) {
// Create a promise that rejects in
const id = setTimeout(() => {
clearTimeout(id);
const boom = Boom.gatewayTimeout('Timed out in ' + ms + 'ms.');
// @ts-ignore
boom.isTimeout = true;
reject(boom);
}, ms);
});
formatResponse: function(error, Log) {
try {
var response = {};
if (error.type) {
switch (error.type) {
case this.types.BAD_IMPLEMENTATION:
response = Boom.badImplementation(error.message);
break;
case this.types.GATEWAY_TIMEOUT:
response = Boom.gatewayTimeout(error.message);
break;
case this.types.NOT_FOUND:
response = Boom.notFound(error.message);
break;
case this.types.BAD_REQUEST:
response = Boom.badRequest(error.message);
break;
case this.types.CONFLICT:
response = Boom.conflict(error.message);
break;
default:
response = Boom.badRequest(error.message);
}
}
else if (error.isBoom) {
response = error
.catch(function (error) {
Log.error(error);
return reply(Boom.gatewayTimeout('An error occurred.'));
});
};
}).catch(function (error) {
Log.error(error);
reply(Boom.gatewayTimeout("There was a database error while retrieving the owner resource."));
});
}
timeoutId = setTimeout(function () {
return finish(Boom.gatewayTimeout('Client request timeout'));
}, options.timeout);
}
setTimeout(() => {
if (!req.aborted && !req.socket) req.abort();
if (!resolved) {
timeoutReject(Boom.gatewayTimeout('Client request timeout'));
} else {
timeoutResolve();
}
}, timeout);
});
.catch(function (error) {
Log.error('sending welcome email failed:', error);
return reply(Boom.gatewayTimeout('Sending registration email failed.'));
});
}
let params=ctx.request.body
let options={
url:params.url,
screenshot:params.screenshot,
html:params.html,
style:params.style,
script:params.script,
waitFor:params.waitFor,
device:params.device
}
if(!(options=checkOption(options,ctx))) return
ctx.type = options.screenshot.type;
try{
ctx.body=await instance.getImage(options)
}catch (e) {
ctx.body=Boom.gatewayTimeout(e.message||'Service Unavailable').output;
}
}
x:ctx.query.x,
y:ctx.query.y,
width:ctx.query.w,
height:ctx.query.h,
},
omitBackground:ctx.query.o
},
waitFor:ctx.query.waitFor,
device:ctx.query.device
}
if(!(options=checkOption(options,ctx))) return
ctx.type = options.screenshot.type;
try{
ctx.body=await instance.getImage(options)
}catch (e) {
ctx.body=Boom.gatewayTimeout(e.message||'Service Unavailable').output;
}
}