简体   繁体   English

如何处理500个错误

[英]How to handle 500 errors

The MooTools Request.JSONP method only has onRequest, onTimeout and onSuccess events to handle results. MooTools Request.JSONP方法仅具有onRequest,onTimeout和onSuccess事件来处理结果。

I am attempting to call a web API using JSONP, but when there is an error at the service end, our developers return a 500 with valid JSON describing the error. 我正在尝试使用JSONP调用Web API,但是当服务端出现错误时,我们的开发人员会返回500,其中包含描述错误的有效JSON。

Is there a way using MooTools Request.JSONP to catch 500 errors? 有没有一种方法可以使用MooTools Request.JSONP捕获500个错误? (Request.JSON is not an option in our specific case). (在我们的特定情况下,Request.JSON不是一个选项)。

Is the only solution to always return a 200 for JSONP? 唯一始终为JSONP返回200的解决方案吗?

I am using More version 1.4.0.1 我正在使用更多版本1.4.0.1

Cheers. 干杯。

Request.JSONP is just a remote script injection. Request.JSONP只是一个远程脚本注入。 it then evals/serialises the response. 然后评估/序列化响应。 it does not actually rely on XHR and as such, it gives you no way to interpret the HTTP response codes. 它实际上并不依赖XHR,因此,它使您无法解释HTTP响应代码。

If you want to do this, you need to use normal Request.JSON AND enable CORS to allow external domains. 如果要执行此操作,则需要使用常规的Request.JSON并启用CORS以允许外部域。

otherwise, nothing you can do: 否则,您无能为力:

https://github.com/mootools/mootools-more/blob/master/Source/Request/Request.JSONP.js#L85-L104 https://github.com/mootools/mootools-more/blob/master/Source/Request/Request.JSONP.js#L85-L104

you can probably subclass this and add different logic in the success method to fire errors etc when the response if of a particular type, which you have to do on your own w/o the aid of serverside semantics. 您可能可以对此子类化,并在success方法中添加不同的逻辑以引发错误(如果响应是特定类型的话)等,这是您自己完成的,而无需借助服务器端语义。 good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM