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> => {
|
||||
|
||||
@@ -7,11 +7,11 @@ import type { ResourceIdentifier } from '../../../src/ldp/representation/Resourc
|
||||
import type { DataAccessor } from '../../../src/storage/accessors/DataAccessor';
|
||||
import { DataAccessorBasedStore } from '../../../src/storage/DataAccessorBasedStore';
|
||||
import { INTERNAL_QUADS } from '../../../src/util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
|
||||
import { ConflictHttpError } from '../../../src/util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../../../src/util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
import { NotImplementedError } from '../../../src/util/errors/NotImplementedError';
|
||||
import { UnsupportedHttpError } from '../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
import type { Guarded } from '../../../src/util/GuardedStream';
|
||||
import * as quadUtil from '../../../src/util/QuadUtil';
|
||||
import { guardedStreamFrom } from '../../../src/util/StreamUtil';
|
||||
@@ -29,7 +29,7 @@ class SimpleDataAccessor implements DataAccessor {
|
||||
|
||||
public async canHandle(representation: Representation): Promise<void> {
|
||||
if (!representation.binary) {
|
||||
throw new UnsupportedHttpError();
|
||||
throw new BadRequestHttpError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
it('checks if the DataAccessor supports the data.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
representation.binary = false;
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('will 404 if the target does not exist and does not end in a slash.', async(): Promise<void> => {
|
||||
@@ -150,7 +150,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
||||
const resourceID = { path: root };
|
||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('passes the result along if the MetadataController throws a non-Error.', async(): Promise<void> => {
|
||||
@@ -241,7 +241,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
it('checks if the DataAccessor supports the data.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
representation.binary = false;
|
||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('will error if the path has a different slash than the existing one.', async(): Promise<void> => {
|
||||
@@ -266,14 +266,14 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
it('will error if the ending slash does not match its resource type.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}resource/` };
|
||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(
|
||||
new UnsupportedHttpError('Containers should have a `/` at the end of their path, resources should not.'),
|
||||
new BadRequestHttpError('Containers should have a `/` at the end of their path, resources should not.'),
|
||||
);
|
||||
});
|
||||
|
||||
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
|
||||
it('can write resources.', async(): Promise<void> => {
|
||||
@@ -328,7 +328,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
describe('modifying a Representation', (): void => {
|
||||
it('is not supported.', async(): Promise<void> => {
|
||||
await expect(store.modifyResource())
|
||||
.rejects.toThrow(new NotImplementedError('Patches are not supported by the default store.'));
|
||||
.rejects.toThrow(new NotImplementedHttpError('Patches are not supported by the default store.'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
import { RoutingResourceStore } from '../../../src/storage/RoutingResourceStore';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
import { StaticAsyncHandler } from '../../util/StaticAsyncHandler';
|
||||
|
||||
describe('A RoutingResourceStore', (): void => {
|
||||
@@ -61,7 +61,7 @@ describe('A RoutingResourceStore', (): void => {
|
||||
|
||||
it('throws a 404 if there is no body and no store was found.', async(): Promise<void> => {
|
||||
rule.canHandle = (): any => {
|
||||
throw new UnsupportedHttpError();
|
||||
throw new NotImplementedHttpError();
|
||||
};
|
||||
await expect(store.getRepresentation(identifier, 'preferences' as any, 'conditions' as any))
|
||||
.rejects.toThrow(NotFoundHttpError);
|
||||
|
||||
@@ -6,9 +6,9 @@ import type { Quad } from 'rdf-js';
|
||||
import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { SparqlDataAccessor } from '../../../../src/storage/accessors/SparqlDataAccessor';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { ConflictHttpError } from '../../../../src/util/errors/ConflictHttpError';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
import type { Guarded } from '../../../../src/util/GuardedStream';
|
||||
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
|
||||
@@ -214,7 +214,7 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
[ quad(namedNode('http://name'), namedNode('http://pred'), literal('value'), namedNode('badGraph!')) ],
|
||||
);
|
||||
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, data, metadata))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Only triples in the default graph are supported.'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Only triples in the default graph are supported.'));
|
||||
});
|
||||
|
||||
it('errors when the SPARQL endpoint fails during reading.', async(): Promise<void> => {
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
matchingTypes,
|
||||
validateRequestArgs,
|
||||
} from '../../../../src/storage/conversion/ConversionUtil';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { InternalServerError } from '../../../../src/util/errors/InternalServerError';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('ConversionUtil', (): void => {
|
||||
const identifier: ResourceIdentifier = { path: 'path' };
|
||||
@@ -66,7 +66,7 @@ describe('ConversionUtil', (): void => {
|
||||
const preferences: RepresentationPreferences =
|
||||
{ type: [{ value: 'b/x', weight: 1 }, { value: 'b/x', weight: 0 }]};
|
||||
expect((): any => matchingTypes(preferences, [ 'b/x' ]))
|
||||
.toThrow(new UnsupportedHttpError(`Duplicate type preference found: b/x`));
|
||||
.toThrow(new BadRequestHttpError(`Duplicate type preference found: b/x`));
|
||||
});
|
||||
|
||||
it('errors if there invalid types.', async(): Promise<void> => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { RepresentationPreferences } from '../../../../src/ldp/representati
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { CONTENT_TYPE } from '../../../../src/util/UriConstants';
|
||||
|
||||
describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
@@ -80,7 +80,7 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
) ]);
|
||||
});
|
||||
|
||||
it('throws an UnsupportedHttpError on invalid triple data.', async(): Promise<void> => {
|
||||
it('throws an BadRequestHttpError on invalid triple data.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: 'text/turtle' });
|
||||
const representation = {
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.co' ]),
|
||||
@@ -94,6 +94,6 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
metadata: expect.any(RepresentationMetadata),
|
||||
});
|
||||
expect(result.metadata.contentType).toEqual(INTERNAL_QUADS);
|
||||
await expect(arrayifyStream(result.data)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(arrayifyStream(result.data)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import { ExtensionBasedMapper } from '../../../../src/storage/mapping/ExtensionBasedMapper';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { trimTrailingSlashes } from '../../../../src/util/PathUtil';
|
||||
|
||||
jest.mock('fs');
|
||||
@@ -27,12 +27,12 @@ describe('An ExtensionBasedMapper', (): void => {
|
||||
|
||||
it('throws 404 if the relative path does not start with a slash.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${trimTrailingSlashes(base)}test` }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('URL needs a / after the base'));
|
||||
.rejects.toThrow(new BadRequestHttpError('URL needs a / after the base'));
|
||||
});
|
||||
|
||||
it('throws 400 if the input path contains relative parts.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test/../test2` }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Disallowed /.. segment in URL'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Disallowed /.. segment in URL'));
|
||||
});
|
||||
|
||||
it('returns the corresponding file path for container identifiers.', async(): Promise<void> => {
|
||||
@@ -44,7 +44,7 @@ describe('An ExtensionBasedMapper', (): void => {
|
||||
|
||||
it('rejects URLs that end with "$.{extension}".', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test$.txt` }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Identifiers cannot contain a dollar sign before their extension'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Identifiers cannot contain a dollar sign before their extension'));
|
||||
});
|
||||
|
||||
it('throws 404 when looking in a folder that does not exist.', async(): Promise<void> => {
|
||||
@@ -95,7 +95,7 @@ describe('An ExtensionBasedMapper', (): void => {
|
||||
|
||||
it('throws 400 if the given content-type is not recognized.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test.txt` }, 'fake/data'))
|
||||
.rejects.toThrow(new UnsupportedHttpError(`Unsupported content type fake/data`));
|
||||
.rejects.toThrow(new BadRequestHttpError(`Unsupported content type fake/data`));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FixedContentTypeMapper } from '../../../../src/storage/mapping/FixedContentTypeMapper';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { trimTrailingSlashes } from '../../../../src/util/PathUtil';
|
||||
|
||||
jest.mock('fs');
|
||||
@@ -17,12 +17,12 @@ describe('An FixedContentTypeMapper', (): void => {
|
||||
|
||||
it('throws 404 if the relative path does not start with a slash.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${trimTrailingSlashes(base)}test` }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('URL needs a / after the base'));
|
||||
.rejects.toThrow(new BadRequestHttpError('URL needs a / after the base'));
|
||||
});
|
||||
|
||||
it('throws 400 if the input path contains relative parts.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test/../test2` }))
|
||||
.rejects.toThrow(new UnsupportedHttpError('Disallowed /.. segment in URL'));
|
||||
.rejects.toThrow(new BadRequestHttpError('Disallowed /.. segment in URL'));
|
||||
});
|
||||
|
||||
it('returns the corresponding file path for container identifiers.', async(): Promise<void> => {
|
||||
@@ -60,7 +60,7 @@ describe('An FixedContentTypeMapper', (): void => {
|
||||
|
||||
it('throws 400 if the given content-type is not supported.', async(): Promise<void> => {
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test.ttl` }, 'application/n-quads')).rejects
|
||||
.toThrow(new UnsupportedHttpError(`Unsupported content type application/n-quads, only text/turtle is allowed`));
|
||||
.toThrow(new BadRequestHttpError(`Unsupported content type application/n-quads, only text/turtle is allowed`));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { RepresentationMetadata } from '../../../../src/ldp/representation/Repre
|
||||
import { SparqlUpdatePatchHandler } from '../../../../src/storage/patch/SparqlUpdatePatchHandler';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
import type { Lock } from '../../../../src/util/locking/Lock';
|
||||
import type { ResourceLocker } from '../../../../src/util/locking/ResourceLocker';
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
patch: { algebra: {}} as SparqlUpdatePatch };
|
||||
await expect(handler.canHandle(input)).resolves.toBeUndefined();
|
||||
delete (input.patch as any).algebra;
|
||||
await expect(handler.canHandle(input)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle(input)).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('handles INSERT DATA updates.', async(): Promise<void> => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { RepresentationPreferences } from '../../../../src/ldp/representati
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import type { RepresentationConverter } from '../../../../src/storage/conversion/RepresentationConverter';
|
||||
import { PreferenceSupport } from '../../../../src/storage/routing/PreferenceSupport';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
|
||||
describe('A PreferenceSupport', (): void => {
|
||||
const type = 'internal/quads';
|
||||
@@ -26,7 +26,7 @@ describe('A PreferenceSupport', (): void => {
|
||||
|
||||
it('returns false if the converter does not support the input.', async(): Promise<void> => {
|
||||
converter.canHandle = jest.fn((): any => {
|
||||
throw new UnsupportedHttpError();
|
||||
throw new BadRequestHttpError();
|
||||
});
|
||||
await expect(support.supports({ identifier, representation })).resolves.toBe(false);
|
||||
expect(converter.canHandle).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { RegexRouterRule } from '../../../../src/storage/routing/RegexRouterRule';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
|
||||
describe('A RegexRouterRule', (): void => {
|
||||
const base = 'http://test.com/';
|
||||
@@ -9,13 +9,13 @@ describe('A RegexRouterRule', (): void => {
|
||||
it('rejects identifiers not containing the base.', async(): Promise<void> => {
|
||||
const router = new RegexRouterRule(base, {});
|
||||
await expect(router.canHandle({ identifier: { path: 'http://notTest.com/apple' }}))
|
||||
.rejects.toThrow(new UnsupportedHttpError(`Identifiers need to start with http://test.com`));
|
||||
.rejects.toThrow(new BadRequestHttpError(`Identifiers need to start with http://test.com`));
|
||||
});
|
||||
|
||||
it('rejects identifiers not matching any regex.', async(): Promise<void> => {
|
||||
const router = new RegexRouterRule(base, { pear: store });
|
||||
await expect(router.canHandle({ identifier: { path: `${base}apple/` }}))
|
||||
.rejects.toThrow(new UnsupportedHttpError(`No stored regexes match http://test.com/apple/`));
|
||||
.rejects.toThrow(new BadRequestHttpError(`No stored regexes match http://test.com/apple/`));
|
||||
});
|
||||
|
||||
it('accepts identifiers matching any regex.', async(): Promise<void> => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AsyncHandler } from '../../../src/util/AsyncHandler';
|
||||
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
|
||||
import { HttpError } from '../../../src/util/errors/HttpError';
|
||||
import { UnsupportedHttpError } from '../../../src/util/errors/UnsupportedHttpError';
|
||||
import { FirstCompositeHandler } from '../../../src/util/FirstCompositeHandler';
|
||||
import { StaticAsyncHandler } from '../../util/StaticAsyncHandler';
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('A FirstCompositeHandler', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws an UnsupportedHttpError if handlers throw different errors.', async(): Promise<void> => {
|
||||
it('throws an BadRequestHttpError if handlers throw different errors.', async(): Promise<void> => {
|
||||
handlerTrue.canHandle = async(): Promise<void> => {
|
||||
throw new HttpError(401, 'UnauthorizedHttpError');
|
||||
};
|
||||
@@ -120,7 +120,7 @@ describe('A FirstCompositeHandler', (): void => {
|
||||
};
|
||||
const handler = new FirstCompositeHandler([ handlerTrue, handlerFalse ]);
|
||||
|
||||
await expect(handler.canHandle(null)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle(null)).rejects.toThrow(BadRequestHttpError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
|
||||
describe('An UnsupportedHttpError', (): void => {
|
||||
describe('An BadRequestHttpError', (): void => {
|
||||
it('has status code 400.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError('test');
|
||||
const error = new BadRequestHttpError('test');
|
||||
|
||||
expect(error.statusCode).toEqual(400);
|
||||
expect(error.message).toEqual('test');
|
||||
expect(error.name).toEqual('UnsupportedHttpError');
|
||||
expect(error.name).toEqual('BadRequestHttpError');
|
||||
});
|
||||
|
||||
it('has a default message if none was provided.', async(): Promise<void> => {
|
||||
const error = new UnsupportedHttpError();
|
||||
const error = new BadRequestHttpError();
|
||||
|
||||
expect(error.message).toEqual('The given input is not supported by the server configuration.');
|
||||
});
|
||||
Reference in New Issue
Block a user