Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing extensions error field to errorToPlainJson #6029

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/plugins/utils/utils-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function errorToPlainJson(err: Error | TypeError | RxError | RxTypeError)
message: err.message,
rxdb: (err as any).rxdb,
parameters: (err as RxError).parameters,
extensions: (err as any).extensions,
code: (err as RxError).code,
/**
* stack must be last to make it easier to read the json in a console.
Expand Down
1 change: 1 addition & 0 deletions src/types/rx-error.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export type PlainJsonError = {
message: string;
rxdb?: true;
code?: RxErrorKey;
extensions?: Record<string, any>;
parameters?: RxErrorParameters;
stack?: string;
};
Expand Down
26 changes: 25 additions & 1 deletion test/unit/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
toWithDeleted,
stringToArrayBuffer,
arrayBufferToString,
clone
clone,
errorToPlainJson
} from '../../plugins/core/index.mjs';
import config from './config.ts';

Expand Down Expand Up @@ -504,5 +505,28 @@ describe('util.test.js', () => {
assert.strictEqual(str, back);
});
});
describe('.errorToPlainJson()', () => {
it('should return the correct result for an error containing all possible fields', () => {
const customError = {
name: 'CustomError',
message: 'This is a custom error',
rxdb: false,
extensions: { code: 'CUSTOM_ERR_CODE' },
parameters: { value: 'value' },
code: 'CUSTOM_ERR_CODE',
stack: 'CustomError: This is a custom error\n at someFile.js'
};

const result = errorToPlainJson(customError);

assert.strictEqual(result.name, customError.name);
assert.strictEqual(result.message, customError.message);
assert.strictEqual(result.rxdb, customError.rxdb);
assert.deepStrictEqual(result.extensions, customError.extensions);
assert.deepStrictEqual(result.parameters, customError.parameters);
assert.strictEqual(result.code, customError.code);
assert.strictEqual(result.stack, 'CustomError: This is a custom error \n at someFile.js');
});
});
});

Loading