Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('waiting 5s to return from hyperclient createpod')
await new Promise(resolve => {
setTimeout(() => {
console.log('waited 5s to return from hyperclient createpod')
resolve()
}, 5000)
})
if (res.data.Code !== 0) {
console.log('waiting 5s to throw hyperclient')
await new Promise(resolve => {
setTimeout(() => {
console.log('waited 5s to throw hyperclient')
resolve()
}, 5000)
})
throw Boom.serverUnavailable('Could not create pod: hyper error code=' + res.data.Code)
}
return res
}
try {
const body = JSON.parse(req.payload.query);
log.debug('AVERAGE QUERY BODY:', JSON.stringify(body, null, 2));
log.debug('INDEX:', esParams.index);
const resp = await client.search({
index: esParams.index,
ignoreUnavailable: esParams.ignoreUnavailable,
allowNoIndices: esParams.allowNoIndices,
body,
});
return reply(resp);
} catch (err) {
return reply(Boom.serverUnavailable(err.message));
}
}
});
if (responseType !== 'notAcceptable') {
try {
const result = await elastic.get({ index: 'smg', type: 'object', id: TypeMapping.toInternal(request.params.id) });
const relatedItems = await getSimilarObjects(result, elastic);
const sortedRelatedItems = sortRelated(relatedItems);
const JSONData = buildJSONResponse(result, config, sortedRelatedItems);
return response(h, JSONData, 'object', responseType);
} catch (err) {
if (err.status === 404) {
return Boom.notFound(err);
}
return Boom.serverUnavailable('unavailable');
}
} else {
return h.response('Not Acceptable').code(406);
}
}
}
handler: async (request, reply) => {
const items = await getItems();
if (items) {
reply(items);
} else {
reply(Boom.serverUnavailable('Widget load fails 33% of the time. You were unlucky.', {}));
}
},
config: {
export function handleESError(error) {
if (!(error instanceof Error)) {
throw new Error('Expected an instance of Error');
}
if (error instanceof esErrors.ConnectionFault ||
error instanceof esErrors.ServiceUnavailable ||
error instanceof esErrors.NoConnections ||
error instanceof esErrors.RequestTimeout) {
return Boom.serverUnavailable(error);
} else if (error instanceof esErrors.Conflict || _.contains(error.message, 'index_template_already_exists')) {
return Boom.conflict(error);
} else if (error instanceof esErrors[403]) {
return Boom.forbidden(error);
} else if (error instanceof esErrors.NotFound) {
return Boom.notFound(error);
} else if (error instanceof esErrors.BadRequest) {
return Boom.badRequest(error);
} else {
return error;
}
}
try {
const result = await elastic.get({ index: 'smg', type: TypeMapping.toInternal(request.params.type), id: TypeMapping.toInternal(request.params.id) });
var iiifData = buildJSONResponse(result, config);
iiifData.self = config.rootUrl + '/iiif/' + iiifData.data.type + '/' + iiifData.data.id;
return h.response(
Handlebars.compile(
fs.readFileSync(path.join(__dirname, '/../templates/iiif/iiifmanifest.json'), 'utf8')
)(iiifData)
).header('content-type', 'application/json');
} catch (err) {
if (err.status === 404) {
return Boom.notFound();
}
return Boom.serverUnavailable('unavailable');
}
}
}
if (this.settings.maxEventLoopDelay &&
load.eventLoopDelay > this.settings.maxEventLoopDelay) {
throw Boom.serverUnavailable('Server under heavy load (event loop)', load);
}
if (this.settings.maxHeapUsedBytes &&
load.heapUsed > this.settings.maxHeapUsedBytes) {
throw Boom.serverUnavailable('Server under heavy load (heap)', load);
}
if (this.settings.maxRssBytes &&
load.rss > this.settings.maxRssBytes) {
throw Boom.serverUnavailable('Server under heavy load (rss)', load);
}
};
const viewings = runtime.database.get('viewings', debug)
let diagnostic, surveyorIds, viewing
viewing = await viewings.findOne({ uId: uId })
if (!viewing) {
throw boom.notFound('viewingId not valid: ' + uId)
}
surveyorIds = viewing.surveyorIds || []
if (surveyorIds.length !== viewing.count) {
diagnostic = 'surveyorIds invalid found ' + surveyorIds.length + ', expecting ' + viewing.count +
', surveyorId=' + viewing.surveyorId
runtime.captureException(diagnostic, { req: request, extra: { viewing: uId } })
const resp = boom.serverUnavailable(diagnostic)
resp.output.headers['retry-after'] = '5'
throw resp
}
underscore.extend(response, { surveyorIds: viewing.surveyorIds })
try {
verification = registrar.register(proof)
} catch (ex) {
throw boom.badData('invalid registrar proof: ' + JSON.stringify(proof))
}
state = { $currentDate: { timestamp: { $type: 'timestamp' } } }
await credentials.update({ uId: uId, registrarId: registrar.registrarId }, state, { upsert: true })
return underscore.extend(response, { verification })
}
const load = this.load;
if (elapsed > this.settings.sampleInterval) {
load.eventLoopDelay = Math.max(load.eventLoopDelay, elapsed - this.settings.sampleInterval);
}
if (this.settings.maxEventLoopDelay &&
load.eventLoopDelay > this.settings.maxEventLoopDelay) {
throw Boom.serverUnavailable('Server under heavy load (event loop)', load);
}
if (this.settings.maxHeapUsedBytes &&
load.heapUsed > this.settings.maxHeapUsedBytes) {
throw Boom.serverUnavailable('Server under heavy load (heap)', load);
}
if (this.settings.maxRssBytes &&
load.rss > this.settings.maxRssBytes) {
throw Boom.serverUnavailable('Server under heavy load (rss)', load);
}
};
}, async (request, reply) => {
const items = await getItems()
if (items) {
reply(items)
} else {
reply(Boom.serverUnavailable('Widget load fails 33% of the time. You were unlucky.', {}))
}
})