本文整理汇总了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 });
}
},
});
}
开发者ID:gingerwizard,项目名称:kibana,代码行数:35,代码来源:deprecation_logging.ts
示例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 });
}
};
开发者ID:elastic,项目名称:kibana,代码行数:26,代码来源:auth.ts
示例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);
}
},
开发者ID:elastic,项目名称:kibana,代码行数:29,代码来源:search_summary.ts
示例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);
}
},
开发者ID:elastic,项目名称:kibana,代码行数:29,代码来源:contained_search_results.ts
示例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 });
}
};
开发者ID:elastic,项目名称:kibana,代码行数:35,代码来源:on_request.ts
示例6: wrapError
export function wrapError(error: any) {
if (error.isBoom) {
return error;
}
return boomify(error, { statusCode: error.status });
}
开发者ID:gingerwizard,项目名称:kibana,代码行数:7,代码来源:errors.ts
示例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;
}
},
开发者ID:chentsulin,项目名称:apollo-server,代码行数:34,代码来源:hapiApollo.ts
示例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']),
});
},
});
}
开发者ID:,项目名称:,代码行数:36,代码来源:
示例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,
});
}
},
});
}
开发者ID:njd5475,项目名称:kibana,代码行数:25,代码来源:cluster_checkup.ts
示例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);
});
开发者ID:,项目名称:,代码行数:7,代码来源:
注:本文中的Boom.boomify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论