+
Skip to content

HTTP 500 error when sending an invalid application/json request, should instead return HTTP 400 #5804

Open
@Atry

Description

@Atry

Reproduction Steps

Step 1: Add .env file

WRITABLE_PATH=/tmp/uploads
ROOT_URL=http://localhost:4000
PORT=4000
NODE_ENV=development
WITH_API=true

Step 2: Start Server From VS Code

Using the launch.json configuration Meteor: Node

{
"type": "node",
"request": "launch",
"name": "Meteor: Node",
"runtimeExecutable": "meteor",
"runtimeArgs": [
"--port=4000",
"--exclude-archs=web.browser.legacy,web.cordova",
"--raw-logs"
],
"env": {
"WRITABLE_PATH": "/tmp/uploads",
},
"outputCapture": "std",
"restart": true,
"timeout": 60000
},

Step 3: Get an API Token

curl -X POST \
http://localhost:4000/users/login \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{"username": "string", "password": "pa$$word"}'

Step 4: Send an add_comment Request

curl -X POST \
  'http://localhost:4000/api/boards/foo/cards/bar/comments' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer ***************' \
  -H 'Content-Type: application/json'

Actual Output

An HTTP 500 response:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>TypeError: Converting circular structure to JSON<br> &nbsp; &nbsp;--&gt; starting at object with constructor &#39;SimpleSchemaValidationContext&#39;<br> &nbsp; &nbsp;| &nbsp; &nbsp; property &#39;_simpleSchema&#39; -&gt; object with constructor &#39;SimpleSchema&#39;<br> &nbsp; &nbsp;| &nbsp; &nbsp; property &#39;_validationContexts&#39; -&gt; object with constructor &#39;Object&#39;<br> &nbsp; &nbsp;--- property &#39;default&#39; closes the circle<br> &nbsp; &nbsp;at JSON.stringify (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at writeJsonToBody (packages/simple_json-routes.js:157:20)<br> &nbsp; &nbsp;at Object.JsonRoutes.sendResult (packages/simple_json-routes.js:140:3)<br> &nbsp; &nbsp;at models/cardComments.js:342:20<br> &nbsp; &nbsp;at packages/simple_json-routes.js:100:9</pre>
</body>
</html>

Expected Output

An HTTP 400 response due to missing parameters

Server Log

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'SimpleSchemaValidationContext'
|     property '_simpleSchema' -> object with constructor 'SimpleSchema'
|     property '_validationContexts' -> object with constructor 'Object'
--- property 'default' closes the circle
at JSON.stringify (<anonymous>)
at writeJsonToBody (packages/simple_json-routes.js:157:20)
at Object.JsonRoutes.sendResult (packages/simple_json-routes.js:140:3)
at models/cardComments.js:342:20
at packages/simple_json-routes.js:100:9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载