tryError Documentation
Function: diffErrors()
Function
```ts function diffErrors<E1, E2>( error1, error2 ): { context?: { added: Record<string, unknown>; changed: Record< string, { from: unknown; to: unknown; } >; removed: Record<string, unknown>; }; message?: { from: string; to: string; }; source?: { from: string; to: string; }; timestamp?: { from: number; to: number; }; type?: { from: string; to: string; }; }; ``` Defined in: [utils.ts:524](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/utils.ts#L524) Diff two errors to see what changed
tryError API Documentation v0.0.1-alpha.1
tryError API Documentation / diffErrors
Function: diffErrors()
function diffErrors<E1, E2>(
error1,
error2
): {
context?: {
added: Record<string, unknown>;
changed: Record<
string,
{
from: unknown;
to: unknown;
}
>;
removed: Record<string, unknown>;
};
message?: {
from: string;
to: string;
};
source?: {
from: string;
to: string;
};
timestamp?: {
from: number;
to: number;
};
type?: {
from: string;
to: string;
};
};
Defined in: utils.ts:524
Diff two errors to see what changed
Type Parameters
E1
E1
extends TryError
<string
>
E2
E2
extends TryError
<string
>
Parameters
error1
E1
First error
error2
E2
Second error
Returns
{
context?: {
added: Record<string, unknown>;
changed: Record<string, {
from: unknown;
to: unknown;
}>;
removed: Record<string, unknown>;
};
message?: {
from: string;
to: string;
};
source?: {
from: string;
to: string;
};
timestamp?: {
from: number;
to: number;
};
type?: {
from: string;
to: string;
};
}
Object describing the differences
context?
optional context: {
added: Record<string, unknown>;
changed: Record<string, {
from: unknown;
to: unknown;
}>;
removed: Record<string, unknown>;
};
context.added
added: Record<string, unknown>;
context.changed
changed: Record<
string,
{
from: unknown;
to: unknown;
}
>;
context.removed
removed: Record<string, unknown>;
message?
optional message: {
from: string;
to: string;
};
message.from
from: string;
message.to
to: string;
source?
optional source: {
from: string;
to: string;
};
source.from
from: string;
source.to
to: string;
timestamp?
optional timestamp: {
from: number;
to: number;
};
timestamp.from
from: number;
timestamp.to
to: number;
type?
optional type: {
from: string;
to: string;
};
type.from
from: string;
type.to
to: string;
Example
const diff = diffErrors(originalError, modifiedError);
console.log(diff);
// {
// type: { from: "ValidationError", to: "SchemaError" },
// context: { added: { schema: "user" }, removed: { field: "email" } }
// }