mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Assign properties directly to error.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { ConflictHttpError } from '../../../../src/util/errors/ConflictHttpError';
|
||||
import { ForbiddenHttpError } from '../../../../src/util/errors/ForbiddenHttpError';
|
||||
import type { HttpErrorOptions } from '../../../../src/util/errors/HttpError';
|
||||
import { HttpError } from '../../../../src/util/errors/HttpError';
|
||||
import { InternalServerError } from '../../../../src/util/errors/InternalServerError';
|
||||
import { MethodNotAllowedHttpError } from '../../../../src/util/errors/MethodNotAllowedHttpError';
|
||||
@@ -11,8 +12,8 @@ import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/Unsup
|
||||
|
||||
// Only used to make typings easier in the tests
|
||||
class FixedHttpError extends HttpError {
|
||||
public constructor(message?: string) {
|
||||
super(0, '', message);
|
||||
public constructor(message?: string, options?: HttpErrorOptions) {
|
||||
super(0, '', message, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +32,12 @@ describe('HttpError', (): void => {
|
||||
];
|
||||
|
||||
describe.each(errors)('%s', (name, statusCode, constructor): void => {
|
||||
const instance = new constructor('my message');
|
||||
const options = {
|
||||
cause: new Error('cause'),
|
||||
errorCode: 'E1234',
|
||||
details: {},
|
||||
};
|
||||
const instance = new constructor('my message', options);
|
||||
|
||||
it(`is an instance of ${name}.`, (): void => {
|
||||
expect(constructor.isInstance(instance)).toBeTruthy();
|
||||
@@ -48,5 +54,17 @@ describe('HttpError', (): void => {
|
||||
it('sets the message.', (): void => {
|
||||
expect(instance.message).toBe('my message');
|
||||
});
|
||||
|
||||
it('sets the cause.', (): void => {
|
||||
expect(instance.cause).toBe(options.cause);
|
||||
});
|
||||
|
||||
it('sets the error code.', (): void => {
|
||||
expect(instance.errorCode).toBe(options.errorCode);
|
||||
});
|
||||
|
||||
it('sets the details.', (): void => {
|
||||
expect(instance.details).toBe(options.details);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('A BaseIdentifierStrategy', (): void => {
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow('The identifier /unsupported is outside the configured identifier space.');
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow(expect.objectContaining({ options: { errorCode: 'E0001', details: { path: '/unsupported' }}}));
|
||||
.toThrow(expect.objectContaining({ errorCode: 'E0001', details: { path: '/unsupported' }}));
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of a root container.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user