Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): E.Either> {
const { mediaType } = httpContent;
if (exampleKey) {
// the user provided exampleKey - highest priority
const example = findExampleByKey(httpContent, exampleKey);
if (example) {
// example exists, return
return E.right({
code,
mediaType,
bodyExample: example,
});
} else {
return E.left(
ProblemJsonError.fromTemplate(
NOT_FOUND,
`Response for contentType: ${mediaType} and exampleKey: ${exampleKey} does not exist.`
)
);
}
} else if (dynamic === true) {
if (httpContent.schema) {
return E.right({
code,
mediaType,
schema: httpContent.schema,
});
} else {
return E.left(new Error(`Tried to force a dynamic response for: ${mediaType} but schema is not defined.`));
}
} else {
E.fromOption(() => {
logger.warn(outputNoContentFoundMessage(mediaTypes));
return ProblemJsonError.fromTemplate(NOT_ACCEPTABLE, `Unable to find content for ${mediaTypes}`);
})
),
RE.fromOption(() =>
ProblemJsonError.fromTemplate(NOT_FOUND, `Requested status code ${code} is not defined in the document.`)
),