Response codes such ass 200, 404, 500 are very common response codes. Each code has their own meanings and so of course make sure you use them correctly.

I just discovered a case where our API wasn’t returning a JSON and the Mule app started to throw exception when it called the API.

What happens is:

1
return Response::json(['data' => [], 'message' => 'Uh oh'], 204);

is considered as an empty response due to Symfony\Component\HttpFoundation\Response treating code 204 as empty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public function prepare(Request $request)
{
    $headers = $this->headers;

    if ($this->isInformational() || $this->isEmpty()) {
        $this->setContent(null);
        $headers->remove('Content-Type');
        $headers->remove('Content-Length');
        //....

    }
    //....
}

//...

/**
 * Is the response empty?
 *
 * @return bool
 */
public function isEmpty()
{
    return in_array($this->statusCode, array(204, 304));
}

Comments