How can I totally eliminate this 422 (Unprocessable Content) error that is shown in the console? It only happens when validation fails like for instance, the image uploaded exceeds the file size that I required in validation.
Here’s my validation code.
$request->validate([
'message' => 'required|max:5000',
'id' => 'required|integer|exists:users,id',
'content' => 'nullable|integer|exists:contents,id',
'photo' => 'nullable|image|mimes:jpeg,png,jpg|max:2048'
], [
'message.required' => ERR_COMMENT_REQUIRED,
'message.max' => ERR_PHOTO_MAX,
'id.required' => ERR_ID_REQUIRED,
'id.integer' => ERR_ID_INTEGER,
'id.exists' => ERR_ID_EXIST,
'photo.image' => ERR_PHOTO_IMAGE,
'photo.mimes' => ERR_PHOTO_JPG_PNG_GIF,
'photo.max' => ERR_PHOTO_MAX
]);
In my ajax code, I already created an error handler to catch the 422 error and inform the user of what’s going on. It’s perfectly working so far. I just could not figure out how to totally remove the 422 (Unprocessable Content) error in the console window or what is causing it? I’ve been scratching my head all night lol. Hope someone can help me figure out how to solve this. Thanks.
2
Answers
it is not possible. Because it is from browser.
However you can clear the console in error block. But it is not recommended
Laravel validator will return 422 status code on validation fails. You can create validation function as below to return custom status code.