ConnectCorp / nexmo-client

Unofficial Nexmo Rest Client
MIT License
15 stars 13 forks source link

Is there any way to get an error message when the exception is thrown by the message->invoke() method? #25

Open wujekbogdan opened 8 years ago

wujekbogdan commented 8 years ago

When the exception is thrown by the message->invoke() method then I'm unable to get the error code. The only thing I can get is $e->getMessage() that returns just an error message string.

It would be good if there was a method that returns the native Nexmo response

Correct me if I'm wrong.

// Edit:

This is how i solved the problem, but this is not an elegant solution at all.

$message = $e->getMessage();

$response = [
    'status' => null,
    'errorMessage' => $message
];

$errorMessageArray = explode(' - status ', $message);

if (count($errorMessageArray) === 2) {

    $response = [
        'errorMessage' => $errorMessageArray[0],
        'status' => $errorMessageArray[1]
    ];

}
kirkbushell commented 7 years ago

It should be fairly easy to include the raw response as part of the exception, but the point of exceptions in cases like this is to abstract away the underlying specificity and instead include your own messages/codes.