Skip to content

Commit 6e2208a

Browse files
authored
Add nullsafe checks for API response (#505)
1 parent b23db9b commit 6e2208a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Messages/ExceptionErrorHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public function __invoke(ResponseInterface $response, RequestInterface $request)
4040
throw new ClientException\Server($responseBody['title'] . ': ' . $responseBody['detail']);
4141
}
4242

43-
throw new ClientException\Request($responseBody['title'] . ': ' . $responseBody['detail']);
43+
$message = $responseBody['title'] ?? '';
44+
45+
if (isset($responseBody['detail'])) {
46+
$message .= ': ' . $responseBody['detail'];
47+
}
48+
49+
throw new ClientException\Request($message);
4450
}
4551
}

0 commit comments

Comments
 (0)