Laravel 使用404和来自API的响应

Laravel 使用404和来自API的响应,laravel,api,http-status-code-404,response,Laravel,Api,Http Status Code 404,Response,我使用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 a

我使用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):

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

更新: 凭证有效和dd($res)时的屏幕; 也许这会有帮助
您可能需要一个try-catch来处理该异常

共享
dd($res)的结果如何处理错误消息?当有凭证时,我用dd($res)的图像更新问题您可以扩展流对象吗?通常,API会抛出404作为状态代码,但在您的情况下,状态代码是200,并使用自定义代码。发布带有扩展流对象的屏幕截图,直到找到代码。您正在尝试转储响应对象。但是您的代码显示
$res=json\u decode($res->getBody()->getContents(),true)。通过json_解码传递响应内容,然后发布数据结果。
$res = json_decode($res->getBody()->getContents(), true);
dd($res);