mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Rename UnsupportedHttpError into BadRequestError.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
03ffaaed43
commit
af8f1976cd
@@ -7,7 +7,7 @@ import type { MetadataWriter } from '../../../../src/ldp/http/metadata/MetadataW
|
||||
import type { ResponseDescription } from '../../../../src/ldp/http/response/ResponseDescription';
|
||||
import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
|
||||
import { CONTENT_TYPE } from '../../../../src/util/UriConstants';
|
||||
import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler';
|
||||
@@ -27,10 +27,10 @@ describe('A BasicResponseWriter', (): void => {
|
||||
|
||||
it('requires the input to be a binary ResponseDescription.', async(): Promise<void> => {
|
||||
await expect(writer.canHandle({ response, result: new Error('error') }))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
await expect(writer.canHandle({ response, result: { statusCode: 201, metadata }}))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
await expect(writer.canHandle({ response, result }))
|
||||
.resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
|
||||
import type { MockResponse } from 'node-mocks-http';
|
||||
import { createResponse } from 'node-mocks-http';
|
||||
import { ErrorResponseWriter } from '../../../../src/ldp/http/ErrorResponseWriter';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('An ErrorResponseWriter', (): void => {
|
||||
const writer = new ErrorResponseWriter();
|
||||
@@ -16,7 +16,7 @@ describe('An ErrorResponseWriter', (): void => {
|
||||
await expect(writer.canHandle({ response, result: new Error('error') }))
|
||||
.resolves.toBeUndefined();
|
||||
await expect(writer.canHandle({ response, result: { statusCode: 200 }}))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('responds with 500 if an error if there is an error.', async(): Promise<void> => {
|
||||
@@ -27,11 +27,11 @@ describe('An ErrorResponseWriter', (): void => {
|
||||
});
|
||||
|
||||
it('responds with the given statuscode if there is an HttpError.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError('error');
|
||||
const error = new NotImplementedHttpError('error');
|
||||
await writer.handle({ response, result: error });
|
||||
expect(response._isEndCalled()).toBeTruthy();
|
||||
expect(response._getStatusCode()).toBe(error.statusCode);
|
||||
expect(response._getData()).toMatch('UnsupportedHttpError: error');
|
||||
expect(response._getData()).toMatch('NotImplementedHttpError: error');
|
||||
});
|
||||
|
||||
it('responds with the error name and message when no stack trace is lazily generated.', async(): Promise<void> => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { BodyParserArgs } from '../../../../src/ldp/http/BodyParser';
|
||||
import { SparqlUpdateBodyParser } from '../../../../src/ldp/http/SparqlUpdateBodyParser';
|
||||
import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import type { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
|
||||
describe('A SparqlUpdateBodyParser', (): void => {
|
||||
@@ -28,7 +28,7 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
|
||||
it('errors when handling invalid SPARQL updates.', async(): Promise<void> => {
|
||||
input.request = streamifyArray([ 'VERY INVALID UPDATE' ]) as HttpRequest;
|
||||
await expect(bodyParser.handle(input)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(bodyParser.handle(input)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('errors when receiving an unexpected error.', async(): Promise<void> => {
|
||||
@@ -38,7 +38,7 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
input.request = streamifyArray(
|
||||
[ 'DELETE DATA { <http://test.com/s> <http://test.com/p> <http://test.com/o> }' ],
|
||||
) as HttpRequest;
|
||||
await expect(bodyParser.handle(input)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(bodyParser.handle(input)).rejects.toThrow(BadRequestHttpError);
|
||||
mock.mockRestore();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SlugParser } from '../../../../../src/ldp/http/metadata/SlugParser';
|
||||
import { RepresentationMetadata } from '../../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import type { HttpRequest } from '../../../../../src/server/HttpRequest';
|
||||
import { UnsupportedHttpError } from '../../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../../src/util/errors/BadRequestHttpError';
|
||||
import { HTTP } from '../../../../../src/util/UriConstants';
|
||||
|
||||
describe('A SlugParser', (): void => {
|
||||
@@ -22,7 +22,7 @@ describe('A SlugParser', (): void => {
|
||||
it('errors if there are multiple slug headers.', async(): Promise<void> => {
|
||||
request.headers.slug = [ 'slugA', 'slugB' ];
|
||||
await expect(parser.parse(request, metadata))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Request has multiple Slug headers'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Request has multiple Slug headers'));
|
||||
});
|
||||
|
||||
it('stores the slug metadata.', async(): Promise<void> => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DeleteOperationHandler } from '../../../../src/ldp/operations/DeleteOperationHandler';
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A DeleteOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
@@ -12,7 +12,7 @@ describe('A DeleteOperationHandler', (): void => {
|
||||
|
||||
it('only supports DELETE operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'DELETE' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('deletes the resource from the store and returns the correct response.', async(): Promise<void> => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GetOperationHandler } from '../../../../src/ldp/operations/GetOperation
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import type { Representation } from '../../../../src/ldp/representation/Representation';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A GetOperationHandler', (): void => {
|
||||
const store = {
|
||||
@@ -13,7 +13,7 @@ describe('A GetOperationHandler', (): void => {
|
||||
|
||||
it('only supports GET operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('returns the representation from the store with the correct response.', async(): Promise<void> => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { HeadOperationHandler } from '../../../../src/ldp/operations/HeadOperati
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import type { Representation } from '../../../../src/ldp/representation/Representation';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A HeadOperationHandler', (): void => {
|
||||
let store: ResourceStore;
|
||||
@@ -21,8 +21,8 @@ describe('A HeadOperationHandler', (): void => {
|
||||
|
||||
it('only supports HEAD operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'HEAD' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('returns the representation from the store with the correct response.', async(): Promise<void> => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { PatchOperationHandler } from '../../../../src/ldp/operations/PatchOperationHandler';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A PatchOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
@@ -12,7 +12,7 @@ describe('A PatchOperationHandler', (): void => {
|
||||
|
||||
it('only supports PATCH operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'PATCH' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('deletes the resource from the store and returns the correct response.', async(): Promise<void> => {
|
||||
|
||||
@@ -3,7 +3,8 @@ import { PostOperationHandler } from '../../../../src/ldp/operations/PostOperati
|
||||
import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
import { HTTP } from '../../../../src/util/UriConstants';
|
||||
|
||||
describe('A PostOperationHandler', (): void => {
|
||||
@@ -16,11 +17,11 @@ describe('A PostOperationHandler', (): void => {
|
||||
await expect(handler.canHandle({ method: 'POST', body: { }} as Operation))
|
||||
.resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET', body: { }} as Operation))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('errors if there is no body.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.handle({ method: 'POST' } as Operation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('adds the given representation to the store and returns the correct response.', async(): Promise<void> => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { PutOperationHandler } from '../../../../src/ldp/operations/PutOperationHandler';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A PutOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
@@ -12,7 +13,7 @@ describe('A PutOperationHandler', (): void => {
|
||||
});
|
||||
|
||||
it('only supports PUT operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
await expect(handler.canHandle({ method: 'PUT' } as Operation)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -26,6 +27,6 @@ describe('A PutOperationHandler', (): void => {
|
||||
});
|
||||
|
||||
it('errors when there is no body.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'PUT' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.handle({ method: 'PUT' } as Operation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { MethodPermissionsExtractor } from '../../../../src/ldp/permissions/MethodPermissionsExtractor';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A MethodPermissionsExtractor', (): void => {
|
||||
const extractor = new MethodPermissionsExtractor();
|
||||
@@ -11,7 +11,7 @@ describe('A MethodPermissionsExtractor', (): void => {
|
||||
await expect(extractor.canHandle({ method: 'POST' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(extractor.canHandle({ method: 'PUT' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(extractor.canHandle({ method: 'DELETE' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(extractor.canHandle({ method: 'PATCH' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(extractor.canHandle({ method: 'PATCH' } as Operation)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('requires read for HEAD operations.', async(): Promise<void> => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Factory } from 'sparqlalgebrajs';
|
||||
import type { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch';
|
||||
import type { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SparqlPatchPermissionsExtractor } from '../../../../src/ldp/permissions/SparqlPatchPermissionsExtractor';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
|
||||
describe('A SparqlPatchPermissionsExtractor', (): void => {
|
||||
const extractor = new SparqlPatchPermissionsExtractor();
|
||||
@@ -12,14 +12,14 @@ describe('A SparqlPatchPermissionsExtractor', (): void => {
|
||||
const operation = { method: 'PATCH', body: { algebra: factory.createDeleteInsert() }} as unknown as Operation;
|
||||
await expect(extractor.canHandle(operation)).resolves.toBeUndefined();
|
||||
await expect(extractor.canHandle({ ...operation, method: 'GET' }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of GET, only PATCH.'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Cannot determine permissions of GET, only PATCH.'));
|
||||
await expect(extractor.canHandle({ ...operation, body: undefined }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of PATCH operations without a body.'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Cannot determine permissions of PATCH operations without a body.'));
|
||||
await expect(extractor.canHandle({ ...operation, body: {} as SparqlUpdatePatch }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of non-SPARQL patches.'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Cannot determine permissions of non-SPARQL patches.'));
|
||||
await expect(extractor.canHandle({ ...operation,
|
||||
body: { algebra: factory.createMove('DEFAULT', 'DEFAULT') } as unknown as SparqlUpdatePatch }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of a PATCH without DELETE/INSERT.'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Cannot determine permissions of a PATCH without DELETE/INSERT.'));
|
||||
});
|
||||
|
||||
it('requires append for INSERT operations.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user