mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-25 22:50:04 +05:30
#316: implement a very naive Response serialization for logger
This commit is contained in:
parent
c8b278fd72
commit
5039dab2d1
@ -74,15 +74,49 @@ const logger = {
|
||||
};
|
||||
}
|
||||
|
||||
context = abbreviate(context); // prepare data for JSON.stringify
|
||||
prepareContext(context).then((context) => {
|
||||
console[method](message, context); // eslint-disable-line
|
||||
|
||||
console[method](message, context); // eslint-disable-line
|
||||
|
||||
Raven.captureException(message, {
|
||||
level,
|
||||
extra: context
|
||||
Raven.captureException(message, {
|
||||
level,
|
||||
extra: context
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* prepare data for JSON.stringify
|
||||
*
|
||||
* @param {object} context
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
function prepareContext(context) {
|
||||
if (context instanceof Response) {
|
||||
// TODO: rewrite abbreviate to use promises and recursively find Response
|
||||
return context.json()
|
||||
.catch(() => context.text())
|
||||
.then((body) =>
|
||||
abbreviate({
|
||||
type: context.type,
|
||||
url: context.url,
|
||||
status: context.status,
|
||||
statusText: context.statusText,
|
||||
body
|
||||
})
|
||||
);
|
||||
} else if (context.originalResponse instanceof Response) {
|
||||
return prepareContext(context.originalResponse)
|
||||
.then((originalResponse) =>
|
||||
abbreviate({
|
||||
...context,
|
||||
originalResponse
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve(abbreviate(context));
|
||||
}
|
||||
|
||||
export default logger;
|
||||
|
Loading…
Reference in New Issue
Block a user