I am trying when someone sends a post request on the wrong Id then send it back automatically but my code is not responding like that,
here is my code sample
try {
const updateFolder = {
folderName: pureFolderName,
userId: purePartnerName,
slug: pureslug,
folderImage: audioFolderImage,
};
const audioFolder = await AudioFolder.update(updateFolder, {
where: { slug: updateSlug },
});
if (audioFolder) {
res.status(200).redirect('/admin/audio-folder');
} else {
req.flash('error', 'Something went wrong into Inserting data !');
return res.status(302).redirect('back');
}
} catch (error) {
if (error) {
req.flash('error', 'Something went wrong into Inserting data !');
return res.status(302).redirect('back');
}
}
it's showing this on browser Cannot POST /admin/audio-folder/edit/
can anyone give me info about how to handle this?
CodePudding user response:
The issue (I believe) is that the route cannot accept a POST
request.
does your code look like
router.get('/ROUTE', async (req, res, next) => {
// code
});
or
router.post('/ROUTE', async (req, res, next) => {
// code
});
the first only accepts GET
requests, the second only POST
requests.