Added custom error handling for 404,422 and 500 errors.