diff --git a/config/presets/representation-conversion.json b/config/presets/representation-conversion.json index 1029e828d..110524901 100644 --- a/config/presets/representation-conversion.json +++ b/config/presets/representation-conversion.json @@ -79,24 +79,24 @@ { "@id": "urn:solid-server:default:RepresentationConverter", - "@type": "IfNeededConverter", - "IfNeededConverter:_converter": { - "@type": "WaterfallHandler", - "WaterfallHandler:_handlers": [ - { - "@id": "urn:solid-server:default:ContentTypeReplacer" - }, - { - "@id": "urn:solid-server:default:RdfToQuadConverter" - }, - { - "@id": "urn:solid-server:default:QuadToRdfConverter" - }, - { - "@id": "urn:solid-server:default:RdfRepresentationConverter" - } - ] - } + "@type": "WaterfallHandler", + "WaterfallHandler:_handlers": [ + { + "@type": "IfNeededConverter" + }, + { + "@id": "urn:solid-server:default:ContentTypeReplacer" + }, + { + "@id": "urn:solid-server:default:RdfToQuadConverter" + }, + { + "@id": "urn:solid-server:default:QuadToRdfConverter" + }, + { + "@id": "urn:solid-server:default:RdfRepresentationConverter" + } + ] } ] } diff --git a/src/storage/conversion/IfNeededConverter.ts b/src/storage/conversion/IfNeededConverter.ts index 535f447d9..87e273fb0 100644 --- a/src/storage/conversion/IfNeededConverter.ts +++ b/src/storage/conversion/IfNeededConverter.ts @@ -1,10 +1,13 @@ import type { Representation } from '../../ldp/representation/Representation'; import { getLoggerFor } from '../../logging/LogUtil'; import { InternalServerError } from '../../util/errors/InternalServerError'; +import { UnsupportedAsyncHandler } from '../../util/UnsupportedAsyncHandler'; import { matchingMediaTypes } from './ConversionUtil'; import { RepresentationConverter } from './RepresentationConverter'; import type { RepresentationConverterArgs } from './RepresentationConverter'; +const EMPTY_CONVERTER = new UnsupportedAsyncHandler('The content type does not match the preferences'); + /** * A {@link RepresentationConverter} that only converts representations * that are not compatible with the preferences. @@ -13,7 +16,7 @@ export class IfNeededConverter extends RepresentationConverter { private readonly converter: RepresentationConverter; protected readonly logger = getLoggerFor(this); - public constructor(converter: RepresentationConverter) { + public constructor(converter: RepresentationConverter = EMPTY_CONVERTER) { super(); this.converter = converter; } diff --git a/test/unit/storage/conversion/IfNeededConverter.test.ts b/test/unit/storage/conversion/IfNeededConverter.test.ts index 90b52a616..518f8feb0 100644 --- a/test/unit/storage/conversion/IfNeededConverter.test.ts +++ b/test/unit/storage/conversion/IfNeededConverter.test.ts @@ -100,4 +100,17 @@ describe('An IfNeededConverter', (): void => { expect(innerConverter.handle).toHaveBeenCalledTimes(1); expect(innerConverter.handle).toHaveBeenCalledWith(args); }); + + it('does not support conversion when there is no inner converter.', async(): Promise => { + const emptyConverter = new IfNeededConverter(); + const preferences = { type: { 'text/turtle': 0 }}; + const args = { identifier, representation, preferences }; + + await expect(emptyConverter.canHandle(args)).rejects + .toThrow('The content type does not match the preferences'); + await expect(emptyConverter.handle(args)).rejects + .toThrow('The content type does not match the preferences'); + await expect(emptyConverter.handleSafe(args)).rejects + .toThrow('The content type does not match the preferences'); + }); });