mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[kbn/server-route-repository] Use appropriate log level based on HTTP status (#214185)
This commit is contained in:
parent
6d9fc21db9
commit
f2af002a5e
1 changed files with 12 additions and 2 deletions
|
@ -118,6 +118,12 @@ export function registerRoutes<TDependencies extends Record<string, any>>({
|
|||
}
|
||||
|
||||
if (isKibanaResponse(result)) {
|
||||
if (result.status >= 500) {
|
||||
logger.error(() => `HTTP ${result.status}: ${JSON.stringify(result.payload)}`);
|
||||
} else if (result.status >= 400) {
|
||||
logger.debug(() => `HTTP ${result.status}: ${JSON.stringify(result.payload)}`);
|
||||
}
|
||||
|
||||
return result;
|
||||
} else if (isObservable(result)) {
|
||||
const controller = new AbortController();
|
||||
|
@ -135,8 +141,6 @@ export function registerRoutes<TDependencies extends Record<string, any>>({
|
|||
return response.ok({ body });
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
|
||||
const opts = {
|
||||
statusCode: 500,
|
||||
body: {
|
||||
|
@ -156,6 +160,12 @@ export function registerRoutes<TDependencies extends Record<string, any>>({
|
|||
opts.body.attributes.data = error?.data;
|
||||
}
|
||||
|
||||
if (opts.statusCode >= 500) {
|
||||
logger.error(() => error);
|
||||
} else {
|
||||
logger.debug(() => error);
|
||||
}
|
||||
|
||||
return response.custom(opts);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue