本文整理汇总了TypeScript中Boom.boomify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript boomify函数的具体用法?TypeScript boomify怎么用?TypeScript boomify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了boomify函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerDeprecationLoggingRoutes
export function registerDeprecationLoggingRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
server.route({
path: '/api/upgrade_assistant/deprecation_logging',
method: 'GET',
async handler(request) {
try {
return await getDeprecationLoggingStatus(callWithRequest, request);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
server.route({
path: '/api/upgrade_assistant/deprecation_logging',
method: 'PUT',
options: {
validate: {
payload: Joi.object({
isEnabled: Joi.boolean(),
}),
},
},
async handler(request) {
try {
const { isEnabled } = request.payload as { isEnabled: boolean };
return await setDeprecationLogging(callWithRequest, request, isEnabled);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
}
示例2: interceptAuth
return async function interceptAuth(
req: Request,
h: ResponseToolkit
): Promise<Lifecycle.ReturnValue> {
try {
const result = await fn(req, sessionStorage.asScoped(req), toolkit);
if (AuthResult.isValidResult(result)) {
if (result.isAuthenticated()) {
return h.authenticated({ credentials: result.payload });
}
if (result.isRedirected()) {
return h.redirect(result.payload).takeover();
}
if (result.isRejected()) {
const { error, statusCode } = result.payload;
return Boom.boomify(error, { statusCode });
}
}
throw new Error(
`Unexpected result from Authenticate. Expected AuthResult, but given: ${result}.`
);
} catch (error) {
return Boom.internal(error.message, { statusCode: 500 });
}
};
示例3: fetchSummaryBuckets
handler: async request => {
const timings = {
esRequestSent: Date.now(),
esResponseProcessed: 0,
};
try {
const search = <Hit, Aggregations>(params: SearchParams) =>
callWithRequest<Hit, Aggregations>(request, 'search', params);
const summaryBuckets = await fetchSummaryBuckets(
search,
request.payload.indices,
request.payload.fields,
request.payload.start,
request.payload.end,
request.payload.bucketSize,
request.payload.query
);
timings.esResponseProcessed = Date.now();
return {
buckets: summaryBuckets,
timings,
};
} catch (requestError) {
throw Boom.boomify(requestError);
}
},
示例4: fetchSearchResultsBetween
handler: async request => {
const timings = {
esRequestSent: Date.now(),
esResponseProcessed: 0,
};
try {
const search = <Hit>(params: SearchParams) =>
callWithRequest<Hit>(request, 'search', params);
const searchResults = await fetchSearchResultsBetween(
search,
request.payload.indices,
request.payload.fields,
request.payload.start,
request.payload.end,
request.payload.query
);
timings.esResponseProcessed = Date.now();
return {
results: searchResults,
timings,
};
} catch (requestError) {
throw Boom.boomify(requestError);
}
},
示例5: interceptRequest
return async function interceptRequest(
request: Request,
h: ResponseToolkit
): Promise<Lifecycle.ReturnValue> {
try {
const result = await fn(KibanaRequest.from(request, undefined), {
next: OnRequestResult.next,
redirected: OnRequestResult.redirected,
rejected: OnRequestResult.rejected,
setUrl: (newUrl: string | Url) => {
request.setUrl(newUrl);
// We should update raw request as well since it can be proxied to the old platform
request.raw.req.url = typeof newUrl === 'string' ? newUrl : newUrl.href;
},
});
if (OnRequestResult.isValidResult(result)) {
if (result.isNext()) {
return h.continue;
}
if (result.isRedirected()) {
return h.redirect(result.payload).takeover();
}
if (result.isRejected()) {
const { error, statusCode } = result.payload;
return Boom.boomify(error, { statusCode });
}
}
throw new Error(
`Unexpected result from OnRequest. Expected OnRequestResult, but given: ${result}.`
);
} catch (error) {
return Boom.internal(error.message, { statusCode: 500 });
}
};
示例6: wrapError
export function wrapError(error: any) {
if (error.isBoom) {
return error;
}
return boomify(error, { statusCode: error.status });
}
示例7: async
handler: async (request, h) => {
try {
const gqlResponse = await runHttpQuery([request], {
method: request.method.toUpperCase(),
options: options.graphqlOptions,
query: request.method === 'post' ? request.payload : request.query,
});
const response = h.response(gqlResponse);
response.type('application/json');
return response;
} catch (error) {
if ('HttpQueryError' !== error.name) {
throw Boom.boomify(error);
}
if (true === error.isGraphQLError) {
const response = h.response(error.message);
response.code(error.statusCode);
response.type('application/json');
return response;
}
const err = new Boom(error.message, { statusCode: error.statusCode });
if (error.headers) {
Object.keys(error.headers).forEach(header => {
err.output.headers[header] = error.headers[header];
});
}
// Boom hides the error when status code is 500
err.output.payload.message = error.message;
throw err;
}
},
示例8: esoPlugin
// eslint-disable-next-line import/no-default-export
export default function esoPlugin(kibana: any) {
return new kibana.Plugin({
id: 'eso',
require: ['encrypted_saved_objects'],
uiExports: { mappings: require('./mappings.json') },
init(server: Legacy.Server) {
server.route({
method: 'GET',
path: '/api/saved_objects/get-decrypted-as-internal-user/{id}',
async handler(request: Request) {
const namespace = server.plugins.spaces && server.plugins.spaces.getSpaceId(request);
try {
return await (server.plugins as any).encrypted_saved_objects.getDecryptedAsInternalUser(
SAVED_OBJECT_WITH_SECRET_TYPE,
request.params.id,
{ namespace: namespace === 'default' ? undefined : namespace }
);
} catch (err) {
if ((server.plugins as any).encrypted_saved_objects.isEncryptionError(err)) {
return badRequest('Failed to encrypt attributes');
}
return boomify(err);
}
},
});
(server.plugins as any).encrypted_saved_objects.registerType({
type: SAVED_OBJECT_WITH_SECRET_TYPE,
attributesToEncrypt: new Set(['privateProperty']),
attributesToExcludeFromAAD: new Set(['publicPropertyExcludedFromAAD']),
});
},
});
}
示例9: registerClusterCheckupRoutes
export function registerClusterCheckupRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const isCloudEnabled = _.get(server.plugins, 'cloud.config.isCloudEnabled', false);
server.route({
path: '/api/upgrade_assistant/status',
method: 'GET',
options: {
pre: [EsVersionPrecheck],
},
async handler(request) {
try {
return await getUpgradeAssistantStatus(callWithRequest, request, isCloudEnabled);
} catch (e) {
if (e.status === 403) {
return Boom.forbidden(e.message);
}
return Boom.boomify(e, {
statusCode: 500,
});
}
},
});
}
示例10: it
it('throw non-401 boom errors.', async () => {
const request = requestFixture();
const non401Error = Boom.boomify(new TypeError());
server.plugins.security.getUser.withArgs(request).rejects(non401Error);
await expect(isAuthenticated(request)).rejects.toThrowError(non401Error);
});