Help with Json Ajax response return code 400 or 500

Help with Json Ajax response return code 400 or 500

Hi all

I want to send a 400 or 500 response from the server and look what happened. I know how to do it if a send a 200 in

success: function(data){
.....
}

but I want to do it well in

error: function (XMLHttpRequest, textStatus, errorThrown){
.....
}

Thanks for your help!!