Stripe API Response: The Data Couldn't Be Read Because It Isn't in The Correct Format

The data couldn’t be read because it isn’t in the correct format Stripe

It looks like onCall returns a data structure that's different than what you expect: https://firebase.google.com/docs/functions/callable-reference

I think you may want to use onRequest instead: https://firebase.google.com/docs/functions/http-events#using_express_request_and_response_objects

The data couldn't be read because it isn't in the correct format

yes ,there is an issue in your model you don't need to use the (Response) only use the Model (ResultItem) the JSON isn't complex JSON like that it just array of (ResultItem)

private func getData(from url: String) {
let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: { data, response, error in
guard let data = data, error == nil else {
print("something went wrong")
return
}
do {
let result = try JSONDecoder().decode([ResultItem].self, from: data)
print(result)
}
catch {
print("failed to convert\(error.localizedDescription)")
}

})
task.resume()
}

struct ResultItem: Codable {
let categorie: String
}

Swift : The data couldn’t be read because it isn’t in the correct format

Just your Album model is incorrect.

struct Album: Codable {
var source : Source
var id : String

enum CodingKeys: String, CodingKey {
case source = "_source"
case id = "_id"
}
}

struct Source: Codable {
var nome : String
var endereco : String?
var uf : String?
var cidade : String?
var bairro : String?
}

If you don't want _id altogether then simply remove the related parts.

As for your Alamofire related code, that part is good.


Notable improvements:

  • Have avoided underscored variable name in model by customizing CodingKeys for key mapping purpose
  • Typenames should always start with a Capital letter (so _source is Source)

    • Similarly, variable names should always start with a lowercase letter
  • Made some variables optional (based on your updated response)

    • Keeping a variable non-optional means it must be present in the response for the model to be created
    • Making a variable optional means that key may or may not be present in the response and it not being there won't prevent the model from being created

Asp.Net - Stripe payment intent working locally but error 502 online

I finally know what was the problem so I'll explain what it was and how to solve it if someone encounters the same error.

The first thing I did was, as suggested by karllekko, to check the server logs when it was running on the hosted service. For that, I used Serilog which is a package that allows you to store the logs into a file (It was the simpliest solution for me).
I then got a more precise error :

HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time...

From this error, I knew I wasn't able to get to stripe's servers. I found a simple ping function in C# that checks if my assumption was right and it was.

I then checked with my host service provider how I could access an external IP: they use a proxy server for security reasons.

I added this code before creating the payment intent which uses the proxy server :

var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxyServer),
UseProxy = true,
};
var httpClient = new HttpClient(handler);

var stripeClient = new StripeClient(
apiKey: secretApiKey,
httpClient: new SystemNetHttpClient(httpClient)
);
StripeConfiguration.StripeClient = stripeClient;

I hope if someone encounters the same error he will be able to solve the problem with this answer.



Related Topics



Leave a reply



Submit