jambonz / jambonz-api-server

jambones REST APIs
MIT License
8 stars 22 forks source link

API server returns incorrect HTTP status code #326

Open javibookline opened 1 month ago

javibookline commented 1 month ago

https://github.com/jambonz/jambonz-api-server/blob/d33d0aa5199eb5c8da649110f19e070659b031dc/lib/routes/api/error.js#L16-L18

When trying to create a resource that already exists, the code returned is 422 (unprocessable resource) when it should return a 409 (conflict).

javibookline commented 1 month ago

The reason it is useful to return the proper code is that it enables better handling of the response - trying to insert something unprocessable should maybe trigger a manual review (i.e. when inserting a carrier bound to an account, the account does not exist) whereas inserting a duplicate entry does not require that, and automated flows benefit from this distinction.