I have a post api that I can't get the error message, because he executes exemple the post and laravel sends me to the Stack page with the error:
Client error: `POST https://****/api/core/members?key=****` resulted in a `403 Forbidden` response: { "errorCode": "1C292\/4", "errorMessage": "USERNAME_EXISTS" }
I would need that if he finds an error, like in this case the "errorCode": "1C292\/4", he doesn't execute the code but puts an alert on my page, how to do that?
public function postRegister(Request $request) {
$endpoint = 'https://***/api/core/members?key=***';
$options = [
'form_params' => [
'name' => $request->name,
'email' => $request->email,
]
];
$client = new Client();
$response = $client->post($endpoint, $options);
echo $response->getStatusCode();
}
He immediately executes the string $response = $client->post($endpoint, $options) and it gives me error on the screen, how can I parse the errorcode before the post request?