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