mavlink / mavlink2rest

mavlink2rest creates a REST server that provides mavlink information from a mavlink source
MIT License
68 stars 23 forks source link

inappropriate 404 on malformed request #69

Closed rotu closed 1 year ago

rotu commented 1 year ago

When a malformed request is sent, the service responds with a 404 error.

For example, the below code produces a 404 Not Found which is, confusingly, the same status code as if the request was directed to a nonexistent endpoint (e.g. http://localhost:8088/oopsy)

The message body is more appropriate to a different message. Maybe "400 Bad Request", "422 Unprocessable Content", or even "500 Internal Server Error".

Error: ["Failed to parse common message: Error(\"invalid type: null, expected internally tagged enum MavMessage\", line: 1, column: 74)", "Failed to parse ardupilotmega message: Error(\"invalid type: null, expected internally tagged enum MavMessage\", line: 1, column: 74)"]

const response = await fetch("http://localhost:8088/mavlink", {
   method: "POST",
   mode: "cors",
   headers: {
      "Content-Type": "application/json"
   },
   body: JSON.stringify({
      "header": {
         "system_id": 255,
         "component_id": 240,
         "sequence": 0
      },
      "message": null
   }
   )
})

console.log(response.status, response.statusText)
console.log(await response.text())