mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create ErrorHandler to convert errors to Representations
This commit is contained in:
34
test/unit/util/errors/ErrorUtil.test.ts
Normal file
34
test/unit/util/errors/ErrorUtil.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { assertNativeError, getStatusCode, isNativeError } from '../../../../src/util/errors/ErrorUtil';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
describe('ErrorUtil', (): void => {
|
||||
describe('#isNativeError', (): void => {
|
||||
it('returns true on native errors.', async(): Promise<void> => {
|
||||
expect(isNativeError(new Error('error'))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false on other values.', async(): Promise<void> => {
|
||||
expect(isNativeError('apple')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#assertNativeError', (): void => {
|
||||
it('returns undefined on native errors.', async(): Promise<void> => {
|
||||
expect(assertNativeError(new Error('error'))).toBeUndefined();
|
||||
});
|
||||
|
||||
it('throws on other values.', async(): Promise<void> => {
|
||||
expect((): void => assertNativeError('apple')).toThrow('apple');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getStatusCode', (): void => {
|
||||
it('returns the corresponding status code for HttpErrors.', async(): Promise<void> => {
|
||||
expect(getStatusCode(new NotFoundHttpError())).toBe(404);
|
||||
});
|
||||
|
||||
it('returns 500 for other errors.', async(): Promise<void> => {
|
||||
expect(getStatusCode(new Error('404'))).toBe(500);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user