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

Verify error handling in Alchemy Language #96

Closed ruslan-ardashev closed 8 years ago

ruslan-ardashev commented 8 years ago

Return nil NSErrors if no error, return NSError.createWatsonError if a call failed.

Maybe add test cases to test for the presence of NSErrors.

germanattanasio commented 8 years ago

The tricky part with the ALchemy APIs is that they return 200 even with errors so you need to look at the x-alchemyapi-error-msg header which usually contains more information than the statusInfo field in the response.

kweinmeister commented 8 years ago

@germanattanasio Are you aware of any specific examples of that behavior (to help us get the ball rolling on a test case)?

vherrin commented 8 years ago

@germanattanasio - I'm seeing the same info in statusInfo vs response in the header. Still no error code value though.

Response Body

{ "status": "ERROR", "statusInfo": "cannot-retrieve:operation-timeout:cannot-resolve-dns", "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html", "url": "http://itwillnotwork.comm", "totalTransactions": "5", "imageKeywords": [] }

Response Code

200

Response Headers

{ "x-backside-transport": "OK OK", "connection": "Keep-Alive", "transfer-encoding": "chunked", "access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept, Authorization", "access-control-allow-origin": "*", "cache-control": "no-cache", "content-type": "application/json", "date": "Tue, 01 Dec 2015 22:25:23 GMT", "server": "nginx", "x-alchemyapi-currentversion": "12.22", "x-alchemyapi-error-msg": "cannot-retrieve:operation-timeout:cannot-resolve-dns", "x-alchemyapi-key": "", "x-alchemyapi-params": "sentiment=0&knowledgeGraph=1&detectedLanguage=unknown&submitLanguage=detect", "x-alchemyapi-raw-content-size": "0", "x-alchemyapi-requested-url": "http://itwillnotwork.comm", "x-alchemyapi-retrieved-url": "http://itwillnotwork.comm", "x-alchemyapi-status": "ERROR", "x-alchemyapi-total-transactions": "5", "x-cf-requestid": "23f80810-ed43-40e5-795f-f0a6bc93af7f", "x-powered-by": "Express", "x-client-ip": "32.97.110.60", "x-global-transaction-id": "3139315927" }

germanattanasio commented 8 years ago

THe fact that you are getting

"x-powered-by": "Express"

and

"server": "nginx"

Just make me think that they are using an express app behind a nginx server... Which I would find weird for AlchemyAPIs.. unless you are getting that from the watson-api-explorer bluemix app.

vherrin commented 8 years ago

yeah this was from watson explorer so I can retry using a rest client such as postman