0

I am having issues parsing the response from an API call using Siesta for iOS. After I post the JSON, it fails trying to parse the response.

    resource("/SaveEmailAddress").request(.post, json: SaveEmailAddress.toDictionary()).onSuccess { (entity) in
        completion(entity, nil)
        }.onFailure{ (error) in
            completion(nil, error)
    }

The API is only returning "Success" in the body.

:status: 200 
cache-control: private 
content-type: application/json; charset=utf-8 
server: Microsoft-IIS/10.0 
x-aspnet-version: 4.0.30319 
x-powered-by: ASP.NET 
date: Tue, 23 Oct 2018 03:35:42 GMT 
content-length: 9

"Success"

It is my understanding that "Success" is valid JSON, however, because it is not an array or a dictionary, Siesta is throwing a "Cannot parse server response" error.

error (Siesta.RequestError)
userMessage = (String) "Cannot parse server response"
httpStatusCode = (int?)nil
entity = (Siesta.Entity<Any>?)nil

When I enable the detailed logs for Siesta, it gives me the following error:

Error: RequestError(userMessage: "Cannot parse server response", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.JSONResponseIsNotDictionaryOrArray(actualType: NSTaggedPointerString)), timestamp: 562010225.337566)

Is there a way to force Siesta to accept it as a valid JSON response? If so, what steps specifically do I need to do to make that happen? I have seen other threads recommend adding an extension which has already been done, but isn't working for me.

extension String: Siesta.JSONConvertible { }
ajburt
  • 1
  • 1
  • Do you mean that the server is returning the characters `"Success"` as the body, including the quotation marks? – Paul Cantrell Oct 23 '18 at 01:46
  • Yes. The body only contains "Success" with the quotes. I modified the response above to reflect the message being returned. – ajburt Oct 23 '18 at 03:43
  • It seems like you are trying to parse the String response to a Dictionary or Array. Did you set up the transformer pipeline to do so? Consult [this post](https://stackoverflow.com/questions/46307224/swift-siesta-access-response-raw-data), and [this issue](https://github.com/bustoutsolutions/siesta/issues/176) – user3207158 Nov 03 '18 at 01:47
  • I looked at the other two posts and am not sure how to implement. I am not getting a dictionary or an array back which is the problem. I am only receiving the message "Success" back. "Success" is technically valid Json even though it isn't in a dictionary or array format. Most of my other calls have an array or dictionary. This one does not. I am not sure how to solve this. – ajburt Dec 18 '18 at 23:09

0 Answers0