Skip to content

Unexpected MIME type causes prism to crash  #2605

Description

@RobertCraigie

Current Behavior

The mock server crashes when a request comes in for an endpoint that looks like this

        "requestBody": {
          "description": "...",
          "content": {
            "undefined": {
              "schema": {
                "type": "object",
                "properties": {}
              }
            }
          }
        },

With this error

/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/whatwg-mimetype/lib/mime-type.js:15
      throw new Error(`Could not parse MIME type string "${string}"`);
            ^
Error: Could not parse MIME type string "undefined"
    at new MIMEType (/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/whatwg-mimetype/lib/mime-type.js:15:13)
    at parseMIMEHeader (/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/@stoplight/prism-http/dist/validator/validators/headers.js:9:22)
    at /Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/@stoplight/prism-http/dist/validator/index.js:27:41
    at /Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/fp-ts/lib/Either.js:66:101
    at /Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/fp-ts/lib/function.js:366:46
    at pipe (/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/fp-ts/lib/function.js:305:23)
    at validateInputBody (/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/@stoplight/prism-http/dist/validator/index.js:24:87)
    at /Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/@stoplight/prism-http/dist/validator/index.js:56:142
    at /Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/fp-ts/lib/Either.js:844:60
    at pipe (/Users/robert/.npm/_npx/61be57b7fb4720a9/node_modules/fp-ts/lib/function.js:303:23)

Expected Behavior

I would expect the mock server to return an error response instead of crashing.

Possible Workaround/Solution

Workaround in my case is to just fix the mime type. I'm mainly just opening this issue as it'd be great for Prism to be more crash-resistant!

Steps to Reproduce

Sorry I don't have a full reproduction, hopefully the aforementioned endpoint definition is helpful.

Environment

  • Version used: v5.11.0
  • Environment name and version (e.g. Chrome 39, node.js 5.4): nodejs v21
  • Operating System and version (desktop or mobile): MacOS
  • Link to your environment/workspace/project: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions