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
Help needed with json response erroring when 200 code response #35
Comments
So I'm still trying to figure out this bug I've created, and it seems like the response json is sending back a content type of "application/json", the api i'm working with only allows me to have the one header of |
Hey! It seems like you set "application/vnd.api+json" value in "Accept" header, but your server responds to you with "application/json" instead, which is why validation fails. Can you elaborate more on what do you mean by "API will not authenticate API call"? |
when i use "application/json" instead as the "Accept" value in swift, my rails server response is like this you can see that |
Ok, so here's my thoughts on this
We will develop feature that will allow changing acceptable content types for 3.1 release. I will leave this issue open for now. |
I implemented this on master: eb7e053 Now you will be able to customize validations however you like. For example, if you want to validate only status codes and not validate mime types, you can do: let request: APIRequest<Fetched, FetchFailed> = DataController.tron.request(path)
request.parameters = parameters
request.headers = ["Accept":"application/vnd.api+json"]
request.validationClosure = { $0.validate(statusCode: (200..<300) } I'm not ready to make a release, but you can try installing from master and see if this helps to solve your problem. |
YES! That worked! Thank you very much for your help! Really enjoying TRON for my API needs! Now that I have this everything is working with the updated API security our API developer has been working on. You guys do great work and thanks again for taking your time to help me with this issue! |
I saw a related issue to this problem i'm having already in the closed issues, but the fixes there didn't do the trick for me. I'm getting a json response and without error from my server (200 code) but i'm getting an error from xcode/swift. Below is said error:
{ status code: 200, headers { "Cache-Control" = "max-age=0, private, must-revalidate"; Connection = close; "Content-Type" = "application/json; charset=utf-8"; Etag = "W/\"f49d10c019a7a3b8c095a8da43570f5f\""; Server = thin; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-Meta-Request-Version" = "0.3.4"; "X-Request-Id" = "129f985f-31a5-4fe7-a09b-3e8d0cb4823a"; "X-Runtime" = "0.433514"; "X-XSS-Protection" = "1; mode=block"; } }), data: Optional(653 bytes), error: Optional(Alamofire.AFError.responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType(acceptableContentTypes: ["application/vnd.api+json"], responseContentType: "application/json"))), errorModel: Optional(wecounsel.DataController.FetchFailed))
Here is what the json looks like:
{ "meta" : { "current_user_abilities" : { "facilitator" : false, "provider" : true, "consumer" : false, "org_admin" : false, "admin" : false } }, "data" : [ { "id" : "session-4763-20170422123000", "links" : { "self" : "http:\/\/localhost:3000\/v1\/sessions\/4763\/repeated\/starts\/2017-04-22%2012:30:00%20-0400\/ends\/2017-04-22%2013:30:00%20-0400" }, "type" : "session", "attributes" : { "end" : "2017-04-22 13:30:00", "start" : "2017-04-22 12:30:00", "title" : "Session", "current_user_participates" : true, "description" : "<p>Session with Doc Brown and Austin Consumer for Follow up.<\/p><p>12:30 PM - 01:30 PM EDT<\/p>", "repeat_instance" : true, "session_mode" : "video_session" } } ] }
Here is my functions I'm using:
`
public class DataController {
static let tron = TRON(baseURL: GlobalVariables().baseURL)
// DataController.tron.headerBuilder = HeaderBuilder(defaultHeaders: [:])
return request
}`
func getData(parameters: [String:Any], finished: @escaping () -> Void) { DataController().Get(parameters: parameters, path: "/v1/calendar").perform(withSuccess: { (Fetched) in if let eventsArray = Fetched.response["data"].array { self.events += eventsArray } print(self.events, "here are the events") finished() }) { (FetchFailed) in print(FetchFailed) finished() } }
anyone have any idea of whats going on? i know the json has an array but i don't think thats the issue is it?
The text was updated successfully, but these errors were encountered: