logo
down
shadow

Mark successful siesta response as error


Mark successful siesta response as error

By : Michael Coene
Date : November 17 2020, 03:01 PM
Hope that helps configureTransformer is just a common-case shortcut for the full-featured (but more verbose) arbitrary transformers Siesta’s pipeline supports. Full transformers can arbitrarily convert any response to any other, including success → failure and failure → success. The user guide discusses this a bit.
You can see this in action in the example project, which has a customer transformer that does something very similar to what you want, turning a 404 failure into a success with the content false. It is configured here and defined here. That example does a failure → success transformation, but you should find the code adaptable for your success → failure purposes.
code :


Share : facebook icon twitter icon
How to resolve Primary IP Blocked response error in postman client and get successful response for Cardstream payment ga

How to resolve Primary IP Blocked response error in postman client and get successful response for Cardstream payment ga


By : Saad EL Hanine
Date : March 29 2020, 07:55 AM
hop of those help? Finally I got my answer.
To resolve this error I have discuss with Cardstream support team and they suggested me to whitelist the approved IP Addresses(Static IP address) within the MMS (Merchant Management System).
Why is the response with error code (500) treated as successful response while using interceptor

Why is the response with error code (500) treated as successful response while using interceptor


By : user6775211
Date : March 29 2020, 07:55 AM
wish of those help by returning your object "normally", you tell angular to treat your error as a success.
You have to replace your
code :
  return config;
  return $q.reject(config);
// optional method
'responseError': function(rejection) {
   // do something on error
   if (canRecover(rejection)) {
     return responseOrNewPromise
   }
   return $q.reject(rejection);
}
Swift Siesta redirect response to failure

Swift Siesta redirect response to failure


By : yasmina chikhi
Date : March 29 2020, 07:55 AM
To fix this issue If by “redirect” you mean “transform an HTTP success into a Siesta error,” then yes, this is possible. The pipeline can arbitrarily transform successes into errors and vice versa.
Write a ResponseTransformer that unwraps the .success case, checks whether the error flags are set (whatever they are), and if so returns a newly constructed .failure.
code :
struct APIErrorHandler: ResponseTransformer {
  func process(_ response: Response) -> Response {
    switch response {
      case .success(let entity):
        if let errorMessage = entity.header(forKey: "X-My-API-Error") {
          return logTransformation(
            .failure(Error(userMessage: errorMessage, cause: MyAPIError(), entity: entity)))
        }
        return response

      case .failure:
        return response  // no change
    }
  }
}
service.configure {
  $0.pipeline[.cleanup].add(APIErrorHandler())
}
Swift Siesta access response raw data

Swift Siesta access response raw data


By : Junpeng Liu
Date : March 29 2020, 07:55 AM
this will help All Siesta responses start out as raw data (in the form of the Foundation type Data), then run through the transformer pipeline.
The default transformer pipeline parses JSON, text, and images based on the Content-type header sent by the server. That list doesn’t include PDF, so if your server is sending a content type of application/pdf (or anything that isn’t a JSON, text, or image content type), the response will still be raw Data at the end of the pipeline:
code :
request.onSuccess { entity in
  guard let data = entity.content as? Data else {
    print("Huh, got mystery response:", entity.content)
    return
  }
  // do stuff with data
}
Siesta.LogCategory.enabled = LogCategory.detailed
Siesta JSON Response

Siesta JSON Response


By : Ankush Bindlish
Date : March 29 2020, 07:55 AM
this will help I have set up an API that gives a JSON response as follows: , You can try Decodable
code :
struct Root:Decodable ( 
  let key1:String
  let key2:InnerItem
}

struct InnerItem:Decodable { 
  let intVal:Int
  let strVal:String
}
do {
    let decoder =  JSONDecoder() 
    decoder.keyDecodingStrategy = .convertFromSnakeCase
    let res = decoder.decode(Root.self,from:data)
    print(res.key1) 
}
catch {

    print(error)
 }
shadow
Privacy Policy - Terms - Contact Us © voile276.org