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,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> => {
|
||||
|
||||
Reference in New Issue
Block a user