-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create Siesta.Error.InvalidJSONObject #37
Comments
The error you’re getting is because
…and then:
But wait! Siesta already has that type checking built in. Siesta infers a content transformer’s expected input type from the parameter type of the closure you give, and flags it as an error if the incoming type in the pipeline is wrong. So believe it or not, all you have to do is pass a closure that declares a specific type for the content, but just passes it through unmodified:
And because adding a custom
…or if you’re willing to lean hard on some Swift type inference magic:
That’s all you need! Note that all the code above lets the default content-type-based transformers do their thing, then errors if something other than a JSON-like array or dict came out the other end. If instead you want to attempt to parse everything as JSON, regardless of content type:
By default, Siesta applies JSON parsing only to responses with a content type of You want might want to parse even plain text responses as JSON. To do that, pass |
Mathew — I’m closing this one, but please feel free to keep following up (or reopen if it’s not resolve for you). |
Thanks for the detailed response! That last part was exactly what I was looking for. I assumed that the Error structs were useable since they are "public" structs. I guess I need to go back and read up on that. |
The The causes themselves are public (even though their initializers aren't) so that you can do error-specifc recovery. There’s an example of that in the docs. |
I am attempting throw an error on all "text/*" responses.
I copied the 'TextResponseTransformer' func into my own class in attempt to reduce it to...
Xcode7.2 is giving me this error 'Cannot invoke value of type 'Error.Cause.InvalidJSONObject.Type' with argument list '()'
The text was updated successfully, but these errors were encountered: