Skip to content

Commit

Permalink
Fixed 204 API responses with no content type still fail (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
davereid-pfg committed Nov 18, 2022
1 parent 5859e6c commit 1d9b4d9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Bynder/Api/Impl/AbstractRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function sendRequestAsync($requestMethod, $uri, $options = [])

return $request->then(
function ($response) {
// Some 204 No Content responses have no content type header.
if ($response->getStatusCode() === 204 && !$response->hasHeader('Content-Type')) {
return NULL;
}
$mimeType = explode(';', $response->getHeader('Content-Type')[0])[0];
switch($mimeType) {
case 'application/json':
Expand All @@ -27,9 +31,6 @@ function ($response) {
return (string)$response->getBody();
case 'text/html':
return $response;
// 204 No Content responses have no content type header.
case $response->getStatusCode() == 204:
return $response;
default:
throw new \Exception('The response type not recognized.');
}
Expand Down

0 comments on commit 1d9b4d9

Please sign in to comment.