expo camera react native - react-native

I am using the expo camera feature to submit scanned images. I have used TakePicutreAsync and have a base64 image. The scan is working fine. But at the time of submitting images, there following is the server error when I try to send a HTTP POST request in try catch block,
Cannot read properties of undefined (reading '1')
and on front end it errors the partial request body (everything minus the features, see below) and that is the error object from which I can make no sense of the error.
I am using formData to form my request as below:
const body = {
frontImg: frontImageBase64,
backImg: backImageBase64
}
var obj1 = {"content": JSON.stringify(body)};
var obj2 = [{"type": "LABEL_DETECTION"}];
formData['image'] = obj1;
formData['features'] = obj2;
Here is the complete request formed ( part of which is spit out as error body from try(POST Request) catch block
FormData {
"_parts": Array [],
"features": Array [
Object {
"type": "LABEL_DETECTION",
},
],
"image": Object {
"content": "{\"frontImage\":\"/9j/4AAQSkZJRgABAQAAAQABAAD/4g...
}
}
What could be going wrong in submitting images or how do I debug with the error message being same as the request body with just image property and not features and nothing else?
Below is the error object body for reference.
error Object {
"config": Object {
"adapter": [Function xhrAdapter],
"data": "{\"_parts\":[],\"image\":{\"content\":\"{\\\"frontImage\\\":\\\"/9j/4AAQSkZAAAAA...

Related

Saving a Postman collection variable from he response body

Trying to figure out why I cannot get this to work? Also, console does not give much of a result.
Scenario:
Making the POST request to get the response with TOKEN
Save the response token to collection variable (as the collection file will be used for importing to another testing solution in the cloud)
Using that collection variable to log out from the session
So, I need to be able to store this as a collection variable and use that token when logging out from the session/DELETE the API admin session.
Error in the console:
There was an error in evaluating the test script: JSONError: Unexpected token 'o' at 1:2 [object Object] ^
Tests:
var response = pm.response.json()
var jsonData = JSON.parse(response)
pm.collectionVariables.set("token", jsonData.response.token);
Response body:
{
"response": {
"token": "***"
},
"messages": [
{
"code": "0",
"text": "OK"
}
]
}
Thank you very much for any advice!
JSON.parse(responseBody) always gets a json representation of the response.
A complete fail safe approach would be:
pm.test("response is ok", ()=>{
pm.response.to.have.status(200)
})
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);
Here's the approach i used.
Send the request
Check if there response is 200
If it's true set the token
pm.test("response is ok", ()=>{
if( pm.response.to.have.status(200)){
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);
}
})
You need to change your status code depending on the condition.
Hope it helps

How to send multiple Validation Errors to React using Flask and Marshmallow in Backend and Axios for React-Native in Frontend

I am using Marshmallow to validate incoming fields for a simple put request.
Now I am testing the error handling in the frontend to make sure I send the right error messages for the frontend.
I am usually sending data of type
{
password: string,
email: string
}
For now Marshmallow checks if the password is long enough and if the email is of format Email.
I collect all errors in a expect statement and send it to the frontend like this:
except ValidationError as err:
return make_response(
{"errors": err.messages}, status.HTTP_400_BAD_REQUEST
)
with Postman giving me e.g. this response:
{
"errors": {
"email": [
"Missing data for required field."
],
"password": [
"Missing data for required field."
],
}
}
All error messages are therefore collected within the field errors and sent back to the frontend.
When the error is sent back to the frontend I catch my error and all I get is this object:
Object {
"data": null,
"error": [Error: Request failed with status code 400],
}
How do I correctly send or receive the
errors: err.messages
field in the frontend within a make_response error response?
I found the solution to the problem I had here:
github.com/axios/axios/issues/960.
Apparently you have to access the response object or the error object that is send to axios. There is no interceptor needed. What I changed was this line, when resolving the promise to:
try {
resolved.data = await promise;
} catch (e) {
resolved.error = e.response.data;
}
before that I accessed the error with:
try {
resolved.data = await promise;
} catch (e) {
resolved.error = e;
}
The errors are stored within the response.data.

POSTMAN COLLECTION RUNNER: passing the all body post request as a variable?

I have a POST request template - instead putting all the JSON body i put a variable: {{bodyRequest}}
now i have a json file that looks like this(Below code bloc) that i upload in my collection runner as data json: my intention is to fetch {{bodyResponse}} from the iteration and make the post call in the api.
[
{ "{{bodyRequest}}":
{
"order": {
"order_date":"{{$timestamp}}",
"order_number":"{{$guid}}",
"reference":"Scenario1",
"destination":
{
"name":"test",
"phone":"00000",
"email":"test#test.com",
"company":"My Company",
"building":"My Building",
"street":"my street",
"suburb":"my sububr",
"post_code":"my postcode",
},
}
}
}
]
Then i click run
Open Collection Runner
Add Data file in Format JSON (above in code)
declare it as Json
run collection
Error Log
Request Body:"{{bodyRequest}} "
instead the all payload
thank you so much
Franco

Get Method is not working inside App if URL contains .info?

I am making a simple GET Method inside the APP , But its Not Working on some URL..
For Eg :
https://lievensberg.webcamconsult.com/wachtkamer/ZwXIk9KcYvMBFeJWiSeUQQ.json . - this is working (contains .com)
https://soa-webcamconsult.sense.info/wachtkamer/pk3rs51FpFUQkrHOJ0uBHg.json - this is not working (contains .info)
Both URL is Working Perfect in Browser...!
I am using AFNetworking, Any one can Help Me Please ?
This is the Call Method , Url given below
//https://soa-webcamconsult.sense.info/wachtkamer/pk3rs51FpFUQkrHOJ0uBHg.json
NSDictionary *header = [NSDictionary dictionaryWithObjectsAndKeys:#"application/json",#"Content-Type", #"application/json", #"Accept", #"iPhone",#"User-Agent",nil];
NSLog(#"url---%#",url);
NSLog(#"header---%#",[Utilities printJson:header]);
[SSNetworkClient initServerCallWithURL:url requestMethod:SSRequestMethodGET requestSerialize:YES headers:header imageData:nil imageDataName:nil parameters:nil success:^(id object) {
completionBlock(YES,object);
} failure:^(id object) {
failureCompletion(NO,object);
}];
In you response of second url you are getting invalid json and which should be like this,
{
"status": {
"code": "on_time",
"message": "U bent op tijd",
"content": "Uw afspraak begint om *|afspraak_tijd|* ."
},
"slave": {
"name1": "Dhr. sunny",
"name2": "Meneer sunny"
},
"master": {
"name1": "Mr beheerder"
},
"push": {
"origin": "pubsub.pubnub.com",
"pub_key": "pub-c-a6ca4c51-0a6f-475d-8f93-f53f48ba117b",
"sub_key": "sub-c-97578f62-3587-11e3-be49-02ee2ddab7fe",
"uuid": "sunny-5a323ac22cacff0004c2a717",
"channels": ["5a29524f2b4faa000470384a", "5a323ac22cacff0004c2a717"]
},
"lobby_message": "",
"contact_info": "/dyncontent/pk3rs51FpFUQkrHOJ0uBHg"
}
Above is the correct json which you will need to improve in your api response
And if you wont verify just create the json file with above json it will work perfectly with browser and with your .info api response json it won't work so you need to improvise your .info json file response
My Mozilla browser Quantum version response,

Unnable to make Google Cloud Messaging Work

I followed the new tutorial Implementing GCM Client on Android, and I'm unnable to make it work.
I get the token form my device succesfully, and when I send the following message
{
"to": "f19jCbaw-S4:APA91b....",
"notification": {
"body": "body",
"title": "title"
},
"data": {
"message": "test"
}
}
to https://gcm-http.googleapis.com/gcm/send, I get the result:
{
"multicast_id": 844556567...,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1433092445706613%..."
}
]
}
But my app is never entering into the the onMessageReceived of MyGcmListenerService class. The only clue that I have is the following log trace:
6399-6454/com.miapp.app W/GcmNotification﹕ Failed to show notification: Missing icon
I'm duplicated step by step the Google Cloud Messaging Quickstart sample project. Obviusly I use my api key and my sender id... but id does not work, my app never stops in my onMessageReceived method.
Anybody else is having this problem?
In fact the payload without notification should reach the "onMessageReceived" method and work fine, but if the notification is present into the payload, the same error is displayed "Failed to show notification: Missing icon".
I tried to set the icon inside the AndroidManifest.xml (on the both intent-filter, on the receiver), but nothing worked.
If you do not require notification, just remove them from the payload.
And if you need the notification, you need to add another required field inside the notification:
If your icon is inside the mipmap you can add:
"icon" : "ic_launcher"
if your icon is inside the drawable, you should have:
"icon" : "#drawable/ic_myicon"
So your new request would look like:
{
"to": "f19jCbaw-S4:APA91b....",
"notification": {
"body": "body",
"title": "title",
"icon" : "#drawable/ic_myicon"
},
"data": {
"message": "test"
}
}