swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Supplying a malformed JSON payload correctly returns a "SyntaxError: Unexpected token" but it is returned as a 200 status code.

Open AlexAllocated opened this issue 9 years ago • 3 comments

Swagger-ui version: 2.2.8

  /reports/generate/{templateName}:
    post:
      summary: Combine provided data with the specified markup template to generate a complete report and optionally create and store as a PDF attachment in Salesforce.
      description: Generates a complete report using the specified template and returns the completed markup. Will also create and store PDF attachment in Salesforce if employeeId and sfId (CAD SF ID) are specified.
      parameters:
        - name: templateName
          in: path
          description: The name of the desired template.
          required: true
          type: string
        - name: data
          in: body
          description: The data payload required to generate a report using the desired template.
          required: true
          schema:
            type: object
            properties:
              employeeId:
                type: string
              sfId:
                type: string
              reportName:
                type: string
              reportData:
                type: object

If you supply a random string for the body (data) the response body correctly contains the parsing error SyntaxError: Unexpected token but the status code is 200.

image

Similarly, if you supply an empty JSON payload it correctly says ValidationError: "data" is required but again the response code is 200.

image

AlexAllocated avatar Jun 19 '17 23:06 AlexAllocated

Can you try the latest version?

webron avatar Jun 20 '17 00:06 webron

Updating swagger-ui to 3.0.16 did not solve the issue.

AlexAllocated avatar Jun 20 '17 00:06 AlexAllocated

Nevermind I'm dumb. My error route handler in express wasn't reading the status code from the error given back.

AlexAllocated avatar Jun 20 '17 01:06 AlexAllocated