使用 404 和来自 API 的响应

Work with 404 and response from an API

我使用 API 检查优惠券代码是否存在。如果优惠券代码存在,一切都很好,但问题是当我输入错误的代码时,我得到这个:

Client error: `GET https://apidev.example.co.uk/api/v1/vouchers/2869512_1-9FDS` resulted in a `404 Not Found` response:
{
"Code": 1000,
"Description": "Voucher no. is unknown please check and try again or contact Acorne on 0330 111 04 (truncated...)

我在后端有这段代码 (laravel php):

$res = json_decode($res->getBody()->getContents(), true);
dd($res);

如何访问代码 1000,并删除此错误屏幕?

更新: 优惠券有效和 dd($res) 时的屏幕;

也许这会有所帮助 似乎 try catch 可能是该异常所需要的