You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My problem is that I need to show a particular message when an admin tries to create a new user with an already used email.
The API returns this when it happens:
Response status code: 400
Response body: - Toggle response
{
"@context": "\/contexts\/ConstraintViolationList",
"@type": "ConstraintViolationList",
"hydra:title": "An error occurred",
"hydra:description": "email: This value is already used.",
"violations": [
{
"propertyPath": "email",
"message": "This value is already used."
}
]
}
In my controller however, if I Try/Catch the call to the repository, I only have access to the ClientException (thrown in Mapado\RestClientSdk\RestClient::post), so I can't distinguish the particular "dupplicate email" error from other ones, even if the API sent the information in it's 400 response.
Please help, Merci beaucoup
The text was updated successfully, but these errors were encountered:
The only solution I think of is to access the response in your catch:
try {
// do something that will fail
} catch (Mapado\RestClientSdk\Exception\RestClientException$e) {
$response = $e->getResponse(); // $response should be a Psr\Http\Message\ResponseInterface$body = $response->getBody();
$content = json_decode($body, true);
var_dump($content['hydra:description']); // should dump ""email: This value is already used."
}
Hello,
I have a problem handling 400 response from API.
My problem is that I need to show a particular message when an admin tries to create a new user with an already used email.
The API returns this when it happens:
In my controller however, if I Try/Catch the call to the repository, I only have access to the ClientException (thrown in Mapado\RestClientSdk\RestClient::post), so I can't distinguish the particular "dupplicate email" error from other ones, even if the API sent the information in it's 400 response.
Please help, Merci beaucoup
The text was updated successfully, but these errors were encountered: