Skip to content

422 Unprocessable Content

The request was perfectly formatted, but contained semantic errors. E.g. providing an email address that isn’t valid, but sending it correctly.

Use this for validation errors. E.g., the JSON was perfectly valid, but the ‘age’ field was set to -50. Use 422 to say ‘I understood it, but the data is semantically wrong’.

import { HttpException, post } from 'shokupan';
export const updateProfile = post('/profile', (req) => {
if (req.body.password && req.body.password.length < 8) {
throw new HttpException('Password must be at least 8 characters', 422);
}
// ... update profile
});