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
@@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user