Files
talk/src/core/server/logger/serializers.ts
T
Wyatt JohnsonandGitHub c045f52daa [CORL-649] Migrations (#2597)
* feat: added migration framework

* chore: added premod user status migration

* feat: enhanced error handling of migrations

* fix: added missing argument from abstract method

* fix: another templating blunder

* fix: removed debug code

* feat: enhanced migration tracking

* fix: remove skipping migrations

* feat: moved indexing to migration system

* fix: linting
2019-10-01 16:00:27 +00:00

54 lines
1.3 KiB
TypeScript

import { stdSerializers } from "bunyan";
import { GraphQLError } from "graphql";
import StackUtils from "stack-utils";
import { CoralError, CoralErrorContext } from "coral-server/errors";
import VError from "verror";
interface SerializedError {
id?: string;
message: string;
name: string;
stack?: string;
context?: CoralErrorContext | Record<string, any>;
originalError?: SerializedError;
}
const stackUtils = new StackUtils();
const errSerializer = (err: Error) => {
const obj: SerializedError = {
message: err.message,
name: err.name,
};
if (err.stack) {
// Copy over a cleaned stack.
obj.stack = stackUtils.clean(err.stack);
}
if (err instanceof GraphQLError && err.originalError) {
// If the error was caused by another error, integrate it.
obj.originalError = errSerializer(err.originalError);
} else if (err instanceof CoralError) {
// Copy over the CoralError specific details.
obj.id = err.id;
obj.context = err.context;
// If the error was caused by another error, integrate it.
const cause = err.cause();
if (cause) {
obj.originalError = errSerializer(cause);
}
} else if (err instanceof VError) {
obj.context = VError.info(err);
}
return obj;
};
export default {
...stdSerializers,
err: errSerializer,
};