bone.sync获取所有响应错误状态码 [英] backbone.sync get all response error status codes

查看:111
本文介绍了bone.sync获取所有响应错误状态码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后,我想捕获302错误并重定向到我的登录页面,但是现在xhr.status的状态码为200.

In the end, I want to catch a 302 error and redirect to my login page, but right now xhr.status is getting a status code of 200.

这是我当前的代码:

parentSyncMethod = Backbone.sync
Backbone.sync = (method, model, options) ->
  old_error = options.old_error
  options.error = (xhr, text_status, error_thrown) ->
    if(xhr.status == 302)
      window.location.replace('http://localhost:8080/login')
    else
      old_error?(xhr, text_status, error_thrown)
  parentSyncMethod(method, model, options)

基本上,我认为问题在于当前网页引发了200错误,但是引发302的错误被包装并且没有传播到xhr.status.有没有办法从已进行的所有get,post,put等调用中获取所有状态码响应?

basically I think the problem is that the current webpage is throwing the 200 error, but the one that's throwing the 302 is wrapped and not propagating to the xhr.status. Is there a way to get all status code responses from all the get, post, put, etc. calls that have been made?

推荐答案

302浏览器会自动重定向响应代码,因此您将无法捕获该响应.仅当数据从重定向到的URL返回数据后,您的处理程序才会运行.

302 response codes are automatically redirected by the browser, so you will not be able to catch that response. Your handler will only run once data comes back from the URL that things were redirected to.

我想说的是,您可能应该只返回200并以自己的方式让响应数据发出重定向信号,而不是在此处使用302.

I'd say that instead of using a 302 here, you probably should just return 200 and have the response data signal a redirect in it's own way.

这篇关于bone.sync获取所有响应错误状态码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆