watson-developer-cloud / swift-sdk

:iphone: The Watson Swift SDK enables developers to quickly add Watson Cognitive Computing services to their Swift applications.
https://watson-developer-cloud.github.io/swift-sdk/
Apache License 2.0
877 stars 223 forks source link

Add support for parsing credentials errors #423

Closed glennrfisher closed 7 years ago

glennrfisher commented 8 years ago

Service credentials are checked before any service is contacted. As a result, errors related to invalid credentials do not match the JSON error format advertised by a service.

Since this is a common error that may occur, we should add support for parsing it and producing a meaningful error message.

With synthesize in Text to Speech, for example, such an error would not be parsed by the dataToError function. Instead, it would pass through and be interpreted as WAV data. Verifying the format of the WAV data would fail, resulting in an unhelpful error message: Returned audio is in an unexpected format.

Here is an example of the response that is returned:

<HTML><HEAD><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><TITLE>Watson Error</TITLE></HEAD><BODY><HR><p>Invalid access to resource - /text-to-speech/api/v1/synthesize?accept=audio%2Fogg%3Bcodecs%3Dopus&amp;voice=en-US_MichaelVoice&amp;text=Good%20morning!</p><p>User access not Authorized.</p><p>Invalid UserId and/or Password. Please confirm that your credentials match the end-point you are trying to access. A common error is trying to use credentials from an experimental or beta release against a GA release or vice versa</p><p>Gateway Error Code : ERCD50-LDAP-NODN-ERR</p><p>Unable to communicate with Watson.</p><p>Request URL : https://158.85.132.94:443/text-to-speech/api/v1/synthesize?accept=audio%2Fogg%3Bcodecs%3Dopus&amp;voice=en-US_MichaelVoice&amp;text=Good%20morning!</p><p>Error Id :  stream-dp01-123041852</p><p>Date-Time : 2016-08-22T09:09:28-04:00</p></BODY></HTML>
rhondakayshow commented 8 years ago

I am getting the same error message of unexpected audio format. I am using an English voice. So would this be related to credentials or a problem with accessing the audio. I am creating an iOS app and the error starts with "error was generated Error Domain=com.ibm.watson.developer-cloud.TextToSpeechV1..."

germanattanasio commented 8 years ago

They are working on changing this to be a json response. It will be out soon

glennrfisher commented 8 years ago

Hi @rhondakayshow. Can you check your credentials and try again? Our test suite is passing, so I think the error is caused by invalid credentials.

@germanattanasio Good to hear! That will be a lot easier to parse.

etayluz commented 7 years ago

I'm also finding this error to be quite misleading - banged my head against the wall for a while before seeing this post. thanks!

glennrfisher commented 7 years ago

Thanks for the feedback, @etayluz! That's really helpful for us to understand the SDK's pain points.

@germanattanasio Do you happen to know the status of the JSON response for invalid credentials? Was it shelved or are there still folks working on that?

germanattanasio commented 7 years ago

I think the fix should be there.
If that's not the case can we parse the 401 errors for now?