2015-04-21 17:38
浏览 273


I'm using laravel's defult auth system but I'm sending requests threw ajax. If I am for example on login page and I send some wrong data, it throws me an error into console:

POST http://some.app/auth/login/ 422 (Unprocessable Entity)

but actually it returns some data:

email: ["The email must be a valid email address."]

Same weird acting for registration.

1. how to fix those status codes?

2. how to handle those errors? Just writing data.email and data.password to an user? Isn't there a better solution?

3. what about csrf token? I'm sending it with data but it doesn't seem to require that


图片转代码服务由CSDN问答提供 功能建议

我正在使用laravel的defult auth系统,但我发送请求抛出ajax。 如果我在登录页面上,我发送了一些错误的数据,它会向控制台发出错误:

  POST http://some.app/auth/login/  422(不可处理的实体)


  email:[“电子邮件必须 是一个有效的电子邮件地址。“] 



2。如何处理这些错误? 只需将data.email和data.password写入用户? 是不是有更好的解决方案?

3。 csrf令牌怎么样? 我发送数据但似乎并不需要


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqxafj6830 2015-04-21 19:54

    This is a validation error.

    The information is returned to the $errors variable. You can handle that any way you want but I guess the most obvious action would be to show the error to the user.

    Actually it's better to have a 422 than a 200 (everything OK, for it's not). Since the auth system relies on the validation request, you wouldn't want the controller to proceed (eg by saving data that didn't pass validation).

    解决 无用
    打赏 举报

相关推荐 更多相似问题