Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Iterate over output content types only once when validating
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Biville committed Feb 5, 2020
1 parent 3a8b302 commit d1843ef
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/streaming-pipeline.js
Expand Up @@ -174,17 +174,18 @@ module.exports = class StreamingPipeline extends Writable {
return;
}

const normalizedOutputContentTypes = outputContentTypes
.map((initialContentType) => determineContentTypes(initialContentType).accept);
const unsupportedContentTypeIndex = normalizedOutputContentTypes
.findIndex((contentType) => !canMarshall(contentType));
if (unsupportedContentTypeIndex >= 0) {
const contentType = outputContentTypes[unsupportedContentTypeIndex];
logger(`Unsupported content type ${contentType} for output #${unsupportedContentTypeIndex}`);
callback(new RiffError(
errors.types.UNSUPPORTED_OUTPUT_CONTENT_TYPE,
`Unsupported content-type '${contentType}' for output #${unsupportedContentTypeIndex}`));
return;
const normalizedOutputContentTypes = [];
for (let i = 0; i < outputContentTypes.length; i++) {
const contentType = outputContentTypes[i];
const normalizedOutputContentType = determineContentTypes(contentType).accept;
if (!canMarshall(normalizedOutputContentType)) {
logger(`Unsupported content type ${contentType} for output #${i}`);
callback(new RiffError(
errors.types.UNSUPPORTED_OUTPUT_CONTENT_TYPE,
`Unsupported content-type '${contentType}' for output #${i}`));
return;
}
normalizedOutputContentTypes.push(normalizedOutputContentType);
}

this._wireInputs(transformers);
Expand Down

0 comments on commit d1843ef

Please sign in to comment.