-1
Good night to you all! I am developing an app with React, Node and typescript and was programming a route with post method for inserting data using sqlite database and testing in India but when running the file it returns me an error of Unhandled Promise rejection and I do not know how to treat this event.
this and my route:
routes.post('/points', async(request, response)=>{
const {
name,
email,
whatsapp,
latitude,
longitude,
city,
uf,
items
}=request.body;
await knex('points').insert({
image: 'image_fake',
name,
email,
whatsapp,
latitude,
longitude,
city,
uf,
})
return response.json({sucess: true});
});
in India I make a request of the post type and the json body as follows
{
"name": "Mercado Livre",
"email": "[email protected]",
"whatsapp": "3198774664",
"latitude": "-45.4892729",
"longitude": "-35.4324233",
"city": "BH",
"uf": "MG",
"items": [
1,
2,
6
]
}
the expected was for me to have an "sucess: true;" response according to my Return Response.json({sucess: true});
but he returns me the following:
(Ode:13488) Unhandledpromiserejectionwarning: Error: Insert into points
(city
, email
, image
, latitude
, longitude
, name
, uf
, whatsapp
) values ('BH', '[email protected]', 'image_fake', '-45.4892729', '-35.4324233', 'Mercado Livre', 'MG', '3198774664') - SQLITE_ERROR: table points has no column named Whatsapp
(Ode:13488) Unhandledpromiserejectionwarning: Unhandled Promise rejection. This error either originated by Throwing Inside of an async Function without a catch block, or by rejecting a Promise which was not handled with . (catch). To terminate the Node process on unhandled Promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(Ode:13488) [DEP0018] Deprecationwarning: Unhandled Promise rejections are deprecated. In the Future, Promise rejections that are not handled will terminate the Node.js process with a non-zero Exit code.
could someone help me?
Try catch helped a lot to identify the error and with that I could notice that I had created the name of the wrong Whatsapp variable in the table and with that gave error in insertion.
– fabios