How to use the @stoplight/prism-core.ProblemJsonError.fromTemplate function in @stoplight/prism-core

To help you get started, we’ve selected a few @stoplight/prism-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / prism / packages / http / src / mocker / negotiator / NegotiatorHelpers.ts View on Github external
): 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 {
github stoplightio / prism / packages / http / src / mocker / negotiator / NegotiatorHelpers.ts View on Github external
E.fromOption(() => {
                  logger.warn(outputNoContentFoundMessage(mediaTypes));

                  return ProblemJsonError.fromTemplate(NOT_ACCEPTABLE, `Unable to find content for ${mediaTypes}`);
                })
              ),
github stoplightio / prism / packages / http / src / mocker / negotiator / NegotiatorHelpers.ts View on Github external
RE.fromOption(() =>
            ProblemJsonError.fromTemplate(NOT_FOUND, `Requested status code ${code} is not defined in the document.`)
          ),