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
@@ -6,11 +6,11 @@ import type { Representation } from '../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
|
||||
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { INTERNAL_QUADS } from '../util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../util/errors/BadRequestHttpError';
|
||||
import { ConflictHttpError } from '../util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { NotImplementedError } from '../util/errors/NotImplementedError';
|
||||
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../util/errors/NotImplementedHttpError';
|
||||
import type { Guarded } from '../util/GuardedStream';
|
||||
import {
|
||||
ensureTrailingSlash,
|
||||
@@ -136,7 +136,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
throw new ConflictHttpError('Input resource type does not match existing resource type.');
|
||||
}
|
||||
if (isContainer !== isContainerIdentifier(identifier)) {
|
||||
throw new UnsupportedHttpError('Containers should have a `/` at the end of their path, resources should not.');
|
||||
throw new BadRequestHttpError('Containers should have a `/` at the end of their path, resources should not.');
|
||||
}
|
||||
|
||||
// Potentially have to create containers if it didn't exist yet
|
||||
@@ -144,7 +144,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
}
|
||||
|
||||
public async modifyResource(): Promise<void> {
|
||||
throw new NotImplementedError('Patches are not supported by the default store.');
|
||||
throw new NotImplementedHttpError('Patches are not supported by the default store.');
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<void> {
|
||||
@@ -246,7 +246,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
quads = await parseQuads(representation.data);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
throw new UnsupportedHttpError(`Can only create containers with RDF data. ${error.message}`);
|
||||
throw new BadRequestHttpError(`Can only create containers with RDF data. ${error.message}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Representation } from '../ldp/representation/Representation';
|
||||
import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences';
|
||||
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../util/errors/NotImplementedHttpError';
|
||||
import type { Conditions } from './Conditions';
|
||||
import type { ResourceStore } from './ResourceStore';
|
||||
import type { RouterRule } from './routing/RouterRule';
|
||||
@@ -53,7 +53,7 @@ export class RoutingResourceStore implements ResourceStore {
|
||||
try {
|
||||
return await this.rule.handleSafe({ identifier });
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof UnsupportedHttpError) {
|
||||
if (error instanceof NotImplementedHttpError) {
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
throw error;
|
||||
|
||||
@@ -15,10 +15,10 @@ import type { Guarded } from '../../util/GuardedStream';
|
||||
*/
|
||||
export interface DataAccessor {
|
||||
/**
|
||||
* Should throw an UnsupportedHttpError if the DataAccessor does not support storing the given Representation.
|
||||
* Should throw a NotImplementedHttpError if the DataAccessor does not support storing the given Representation.
|
||||
* @param representation - Incoming Representation.
|
||||
*
|
||||
* @throws UnsupportedHttpError
|
||||
* @throws BadRequestHttpError
|
||||
* If it does not support the incoming data.
|
||||
*/
|
||||
canHandle: (representation: Representation) => Promise<void>;
|
||||
|
||||
@@ -21,7 +21,7 @@ import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { ConflictHttpError } from '../../util/errors/ConflictHttpError';
|
||||
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
|
||||
import { guardStream } from '../../util/GuardedStream';
|
||||
import type { Guarded } from '../../util/GuardedStream';
|
||||
@@ -126,7 +126,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
const triples = await arrayifyStream(data) as Quad[];
|
||||
const def = defaultGraph();
|
||||
if (triples.some((triple): boolean => !def.equals(triple.graph))) {
|
||||
throw new UnsupportedHttpError('Only triples in the default graph are supported.');
|
||||
throw new NotImplementedHttpError('Only triples in the default graph are supported.');
|
||||
}
|
||||
|
||||
// Not relevant since all content is triples
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { RepresentationPreference } from '../../ldp/representation/RepresentationPreference';
|
||||
import type { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences';
|
||||
import { INTERNAL_ALL } from '../../util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { InternalServerError } from '../../util/errors/InternalServerError';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
/**
|
||||
@@ -15,7 +16,7 @@ import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
* @param preferences - Preferences for output type.
|
||||
* @param types - Media types to compare to the preferences.
|
||||
*
|
||||
* @throws UnsupportedHttpError
|
||||
* @throws BadRequestHttpError
|
||||
* If the type preferences are undefined or if there are duplicate preferences.
|
||||
*
|
||||
* @returns The weighted and filtered list of matching types.
|
||||
@@ -23,12 +24,12 @@ import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
export const matchingTypes = (preferences: RepresentationPreferences, types: string[]):
|
||||
RepresentationPreference[] => {
|
||||
if (!Array.isArray(preferences.type)) {
|
||||
throw new UnsupportedHttpError('Output type required for conversion.');
|
||||
throw new BadRequestHttpError('Output type required for conversion.');
|
||||
}
|
||||
|
||||
const prefMap = preferences.type.reduce((map: Record<string, number>, pref): Record<string, number> => {
|
||||
if (map[pref.value]) {
|
||||
throw new UnsupportedHttpError(`Duplicate type preference found: ${pref.value}`);
|
||||
throw new BadRequestHttpError(`Duplicate type preference found: ${pref.value}`);
|
||||
}
|
||||
map[pref.value] = pref.weight;
|
||||
return map;
|
||||
@@ -96,12 +97,12 @@ export const validateRequestArgs = (request: RepresentationConverterArgs, suppor
|
||||
supportedOut: string[]): void => {
|
||||
const inType = request.representation.metadata.contentType;
|
||||
if (!inType) {
|
||||
throw new UnsupportedHttpError('Input type required for conversion.');
|
||||
throw new BadRequestHttpError('Input type required for conversion.');
|
||||
}
|
||||
if (!supportedIn.some((type): boolean => matchingMediaType(inType, type))) {
|
||||
throw new UnsupportedHttpError(`Can only convert from ${supportedIn} to ${supportedOut}.`);
|
||||
throw new NotImplementedHttpError(`Can only convert from ${supportedIn} to ${supportedOut}.`);
|
||||
}
|
||||
if (matchingTypes(request.preferences, supportedOut).length <= 0) {
|
||||
throw new UnsupportedHttpError(`Can only convert from ${supportedIn} to ${supportedOut}.`);
|
||||
throw new NotImplementedHttpError(`Can only convert from ${supportedIn} to ${supportedOut}.`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import rdfParser from 'rdf-parse';
|
||||
import type { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { pipeSafely } from '../../util/StreamUtil';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { validateRequestArgs } from './ConversionUtil';
|
||||
@@ -38,7 +38,7 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
|
||||
});
|
||||
|
||||
const pass = new PassThrough({ objectMode: true });
|
||||
const data = pipeSafely(rawQuads, pass, (error): Error => new UnsupportedHttpError(error.message));
|
||||
const data = pipeSafely(rawQuads, pass, (error): Error => new BadRequestHttpError(error.message));
|
||||
|
||||
return {
|
||||
binary: false,
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdenti
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { APPLICATION_OCTET_STREAM, TEXT_TURTLE } from '../../util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import {
|
||||
encodeUriPathComponents,
|
||||
ensureTrailingSlash,
|
||||
@@ -82,7 +82,7 @@ export class ExtensionBasedMapper implements FileIdentifierMapper {
|
||||
// Would conflict with how new extensions are stored
|
||||
if (/\$\.\w+$/u.test(filePath)) {
|
||||
this.logger.warn(`Identifier ${identifier.path} contains a dollar sign before its extension`);
|
||||
throw new UnsupportedHttpError('Identifiers cannot contain a dollar sign before their extension');
|
||||
throw new NotImplementedHttpError('Identifiers cannot contain a dollar sign before their extension');
|
||||
}
|
||||
|
||||
// Existing file
|
||||
@@ -123,7 +123,7 @@ export class ExtensionBasedMapper implements FileIdentifierMapper {
|
||||
const extension = mime.extension(contentType);
|
||||
if (!extension) {
|
||||
this.logger.warn(`No extension found for ${contentType}`);
|
||||
throw new UnsupportedHttpError(`Unsupported content type ${contentType}`);
|
||||
throw new NotImplementedHttpError(`Unsupported content type ${contentType}`);
|
||||
}
|
||||
filePath += `$.${extension}`;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { posix } from 'path';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import {
|
||||
encodeUriPathComponents,
|
||||
ensureTrailingSlash, isContainerIdentifier,
|
||||
@@ -45,7 +45,7 @@ export class FixedContentTypeMapper implements FileIdentifierMapper {
|
||||
|
||||
// Only allow the configured content type
|
||||
if (contentType && contentType !== this.contentType) {
|
||||
throw new UnsupportedHttpError(`Unsupported content type ${contentType}, only ${this.contentType} is allowed`);
|
||||
throw new NotImplementedHttpError(`Unsupported content type ${contentType}, only ${this.contentType} is allowed`);
|
||||
}
|
||||
|
||||
this.logger.info(`The path for ${identifier.path} is ${filePath}`);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { posix } from 'path';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import type { Logger } from '../../logging/Logger';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { decodeUriPathComponents } from '../../util/PathUtil';
|
||||
|
||||
const { join: joinPath } = posix;
|
||||
@@ -40,7 +40,7 @@ export const getRelativePath = (baseRequestURI: string, identifier: ResourceIden
|
||||
/**
|
||||
* Check if the given relative path is valid.
|
||||
*
|
||||
* @throws {@link UnsupportedHttpError}
|
||||
* @throws {@link BadRequestHttpError}
|
||||
* If the relative path is invalid.
|
||||
*
|
||||
* @param path - A relative path, as generated by {@link getRelativePath}.
|
||||
@@ -50,11 +50,11 @@ export const getRelativePath = (baseRequestURI: string, identifier: ResourceIden
|
||||
export const validateRelativePath = (path: string, identifier: ResourceIdentifier, logger: Logger): void => {
|
||||
if (!path.startsWith('/')) {
|
||||
logger.warn(`URL ${identifier.path} needs a / after the base`);
|
||||
throw new UnsupportedHttpError('URL needs a / after the base');
|
||||
throw new BadRequestHttpError('URL needs a / after the base');
|
||||
}
|
||||
|
||||
if (path.includes('/..')) {
|
||||
logger.warn(`Disallowed /.. segment in URL ${identifier.path}.`);
|
||||
throw new UnsupportedHttpError('Disallowed /.. segment in URL');
|
||||
throw new BadRequestHttpError('Disallowed /.. segment in URL');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ import { RepresentationMetadata } from '../../ldp/representation/RepresentationM
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { guardStream } from '../../util/GuardedStream';
|
||||
import type { ResourceLocker } from '../../util/locking/ResourceLocker';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
@@ -35,7 +35,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
|
||||
public async canHandle(input: {identifier: ResourceIdentifier; patch: SparqlUpdatePatch}): Promise<void> {
|
||||
if (typeof input.patch.algebra !== 'object') {
|
||||
throw new UnsupportedHttpError('Only SPARQL update patch requests are supported');
|
||||
throw new NotImplementedHttpError('Only SPARQL update patch requests are supported');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
const op = input.patch.algebra;
|
||||
if (!this.isDeleteInsert(op)) {
|
||||
this.logger.warn(`Unsupported operation: ${op.type}`);
|
||||
throw new UnsupportedHttpError('Only DELETE/INSERT SPARQL update operations are supported');
|
||||
throw new NotImplementedHttpError('Only DELETE/INSERT SPARQL update operations are supported');
|
||||
}
|
||||
|
||||
const def = defaultGraph();
|
||||
@@ -52,16 +52,16 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
|
||||
if (!deletes.every((pattern): boolean => pattern.graph.equals(def))) {
|
||||
this.logger.warn('GRAPH statement in DELETE clause');
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported');
|
||||
throw new NotImplementedHttpError('GRAPH statements are not supported');
|
||||
}
|
||||
if (!inserts.every((pattern): boolean => pattern.graph.equals(def))) {
|
||||
this.logger.warn('GRAPH statement in INSERT clause');
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported');
|
||||
throw new NotImplementedHttpError('GRAPH statements are not supported');
|
||||
}
|
||||
if (op.where ?? deletes.some((pattern): boolean =>
|
||||
someTerms(pattern, (term): boolean => term.termType === 'Variable'))) {
|
||||
this.logger.warn('WHERE statements are not supported');
|
||||
throw new UnsupportedHttpError('WHERE statements are not supported');
|
||||
throw new NotImplementedHttpError('WHERE statements are not supported');
|
||||
}
|
||||
|
||||
const lock = await this.locker.acquire(input.identifier);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Representation } from '../../ldp/representation/Representation';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { trimTrailingSlashes } from '../../util/PathUtil';
|
||||
import type { ResourceStore } from '../ResourceStore';
|
||||
import { RouterRule } from './RouterRule';
|
||||
@@ -47,7 +48,7 @@ export class RegexRouterRule extends RouterRule {
|
||||
return this.regexes.get(regex)!;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedHttpError(`No stored regexes match ${identifier.path}`);
|
||||
throw new NotImplementedHttpError(`No stored regexes match ${identifier.path}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ export class RegexRouterRule extends RouterRule {
|
||||
*/
|
||||
private toRelative(identifier: ResourceIdentifier): string {
|
||||
if (!identifier.path.startsWith(this.base)) {
|
||||
throw new UnsupportedHttpError(`Identifiers need to start with ${this.base}`);
|
||||
throw new BadRequestHttpError(`Identifiers need to start with ${this.base}`);
|
||||
}
|
||||
return identifier.path.slice(this.base.length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user