mirror of
https://github.com/wassname/talk.git
synced 2026-07-16 11:22:16 +08:00
* 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
54 lines
1.3 KiB
TypeScript
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,
|
|
};
|