项目常见错误及解决方法-http状态码,对应解决方法

来源:互联网 发布:碧眼方瞳 知乎 编辑:程序博客网 时间:2024/06/08 20:06

把在公司项目中遇到的不同http状态码,对应的解决问题,总结下(使用的都是Restangular):

1. 403 forbidden ,删除操作,发现是对应的接口写错,(很奇怪,没有报404,竟然是403),正确的写法是--$rootScope.BaseUrl+"/cmdb/delectTable/"+$scope.classFear.id,当时报错写法-$rootScope.BaseUrl+"/cmdb/delectable/"+$scope.classFear.id

2. 403 forbidden,删除操作,发现改变Restangular 的写法,正确写法是--Restangular.allUrl('/cmdb/deleteAttribute',$rootScope.BaseUrl+'/cmdb/deleteAttribute/'+$scope.classAttr.id).remove(),当时报错写法-Restangular.oneUrl('/cmdb/deleteAttribute',$rootScope.BaseUrl+'/cmdb/deleteAttribute/'+$scope.classAttr.id).remove()

3.400 Bad request,新增操作,请求无效,发现是向后台传递的数据格式不对,对象中包含多个对象,正确写法是--{"id":7,"attribute":"{'Description':'系统编号*','IsDisplayableInList':1,'Mode':0,'length':200,'OwnerName':'SystemId','Type':'STRING'}",  "cmclass":{
    "id":4,
    "tablename":"test04"
    }
},错误写法是 attribute对应的对象,外面还要多加一层“”,即使用JSON.stringify处理下,即可。

原创粉丝点击