In my Flutter app, I'm hitting an API to get the Order details from the server but getting the following exception:
Code:
try {
final url =
Uri.parse('$baseUrl/api/v1/user/order/fetch-by-id');
final response = await http.post(
url,
headers: {
"Host": host,
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
},
body: {
"id": orderId,
},
);
final jsonData = jsonDecode(response.body) as Map<String, dynamic>;
debugPrint('[sufi] jsonData: $jsonData');
if (response.statusCode == 200) {
final orderData = OrderModel.fromJson(jsonData["data"]);
return orderData;
} else {
throw {
'error': jsonData['error'],
'message': jsonData['error']['message']
};
}
} catch (error, stack) {
debugPrint('Err: $error');
debugPrint('Stk: $stack');
rethrow;
}
Error:
FormatException: Missing extension byte (at offset 6)
The error is generating from this line:
final jsonData = jsonDecode(response.body) as Map<String, dynamic>;
But the main culprit is response.body because even if I try to log it, the error still shows up.
I've checked the returned data in Postman and I couldn't find any issue there as well.
Sample Response data:
{
"status": "Success",
"data": {
"order_data": {
"id": "clududu930002l20gdowa7krq",
"end_user_id": "cluc10d00003ucck5p64fv87k",
"origin": {
"id": "clududjn90000l20g6bw0d5we",
"coordinates": [
"35.7128553",
"139.7731321"
],
"note": null,
"precautions": null,
"created_at": "2024-03-30T08:39:56.853Z",
"updated_at": "2024-03-30T08:39:56.853Z",
"is_deleted": false,
},
"destination": {
"id": "clududmlk0001l20gp5ov3z7u",
"coordinates": [
"35.6721222",
"139.7264518"
],
"note": null,
"precautions": null,
"created_at": "2024-03-30T08:40:00.681Z",
"updated_at": "2024-03-30T08:40:00.681Z",
"is_deleted": false,
},
"price": 8690,
"route": "{\"coordinates\":[[139.7731828,35.7128641],[139.77321999999998,35.7127018],[139.773206,35.7125773],[139.77311799999998,35.7125566],[139.7733972,35.711417399999995],[139.7734946,35.7108456],[139.77359909999998,35.7107968],[139.77361009999998,35.710587],[139.7736995,35.7103446],[139.7735395,35.7100299],[139.7729656,35.7075253],[139.7729079,35.707324199999995],[139.77253869999998,35.7066053],[139.7721109,35.7058872],[139.77203,35.7056323],[139.77141989999998,35.7000245],[139.77136840000003,35.6996488],[139.7707319,35.699709299999995],[139.7691714,35.6998217],[139.76899,35.6987576],[139.7690008,35.6987144],[139.76835839999998,35.6990431],[139.7681858,35.699114],[139.76742579999998,35.6994799],[139.7670378,35.699641299999996],[139.76619,35.6998799],[139.7654289,35.7001],[139.7636771,35.7006924],[139.76323019999998,35.7008715],[139.7631055,35.700956999999995],[139.7626098,35.7015317],[139.7624344,35.7016184],[139.7620226,35.7017869],[139.7610163,35.7019447],[139.760224,35.7019838],[139.7583894,35.7019666],[139.75773809999998,35.701935],[139.75700419999998,35.7019924],[139.75660449999998,35.702078],[139.755772,35.702279499999996],[139.75552059999998,35.702296499999996],[139.75530419999998,35.7023355],[139.7536432,35.7027587],[139.75327719999999,35.7028089],[139.749101,35.7031664],[139.74715369999998,35.7031968],[139.74656389999998,35.7031597],[139.7460022,35.7030593],[139.74532109999998,35.702872899999996],[139.7447824,35.7026508],[139.7446797,35.7025848],[139.7439219,35.701926799999995],[139.7435505,35.701544399999996],[139.7432852,35.7012192],[139.7427568,35.7004199],[139.7411108,35.698529199999996],[139.74042889999998,35.6976721],[139.7396914,35.6968652],[139.7392705,35.6962762],[139.73916939999998,35.6962009],[139.7386094,35.6953536],[139.7381701,35.6947788],[139.73803569999998,35.694570299999995],[139.7376,35.694059599999996],[139.7370617,35.693495399999996],[139.7355317,35.6923149],[139.7350607,35.6920664],[139.7345954,35.6918376],[139.734552,35.691767299999995],[139.7342208,35.69161],[139.73392049999998,35.691426199999995],[139.73380749999998,35.6914084],[139.73305539999998,35.690827299999995],[139.7324506,35.690274699999996],[139.73230949999999,35.6901975],[139.7314199,35.6899691],[139.73111889999998,35.689866099999996],[139.7310948,35.6898262],[139.7308565,35.6897204],[139.7307258,35.6895819],[139.7305094,35.6890529],[139.7300694,35.687689899999995],[139.72976110000002,35.6866652],[139.72971429999998,35.686447],[139.7295498,35.6859284],[139.7294339,35.6851815],[139.7293046,35.684190699999995],[139.7293167,35.684049],[139.7292655,35.6840365],[139.7290716,35.6838244],[139.7290143,35.6838154],[139.7275498,35.6820728],[139.7274343,35.6818524],[139.7266142,35.6800728],[139.7264999,35.6798966],[139.7262228,35.679649],[139.7259176,35.67948270000001],[139.7257112,35.679418399999996],[139.7251645,35.6792963],[139.7249991,35.6792192],[139.7246318,35.6789929],[139.7232406,35.678273],[139.7211316,35.677225199999995],[139.7210264,35.6771923],[139.7220765,35.6752007],[139.7221889,35.6750488],[139.722423,35.674825999999996],[139.7227091,35.6746547],[139.72308669999998,35.6744937],[139.72325419999999,35.6743859],[139.7233803,35.6742341],[139.7240622,35.6728613],[139.7241659,35.672573199999995],[139.72452529999998,35.6717343],[139.7260647,35.6721496],[139.7261073,35.6720365]],\"type\":\"LineString\"}",
"viewport": "[[35.7128641,139.7736995],[35.6717343,139.7210264]]",
"payment_id": null,
"payment_status": "PENDING",
},
"driver_data": null
}
Important Notes to be considered:
- The backend is written in Next.JS and deployed in Vercel, when I'm using the Vercel links, only then I'm facing such issues.
- When I'm using localhost for the Server, the issue doesn't occur.
- Most of the other Vercel deployed APIs are working fine.