dotkernel / api

DotKernel's PSR-7 REST style API built around the Mezzio API skeleton.
https://docs.dotkernel.org/api-documentation/
MIT License
35 stars 5 forks source link

Custom middleware for 404 and other custom headers #18

Closed arhimede closed 4 years ago

arhimede commented 4 years ago

All error from the 400 class: 404 402 etc.

should be returned in json format, with headers, without twig

arhimede commented 4 years ago

check the usage of https://github.com/mezzio/mezzio-problem-details

arhimede commented 4 years ago

content-type is important all the time

example:

A server that returns response code 200 or 201 with an empty response body and Content-Type specified as application/json is misconfigured, since an empty string is not valid JSON.

As the OP indicated, specifying responseType: "text" fixes the error, since the empty body is not parsed as JSON.

A workaround is to proceed with responseType: "text" and check if the response body is empty. If the response body is not empty, then call JSON.parse(response).

MarioRadu commented 4 years ago

This issue was done and merged to the 3.0 default branch.