异常消息可以作为有效的JSON返回吗? [英] Can exception messages be returned as valid JSONs?

查看:75
本文介绍了异常消息可以作为有效的JSON返回吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:使用javascript调用microsoft translator api的前端应用程序。



成功的api调用返回到oncomplete js函数没有问题,异常消息作为无效的JSON / js返回,因此无法解释;至少,我还没有找到解释无效JSON / js的方法。



成功和不成功的api调用的头响应是application / x -javascript; charset = utf-8,但不成功的api调用的内容是一个异常消息,它不是有效的application / x-javascript。例如,这里返回了一种
异常消息:
$


" ArgumentException:传入令牌已过期。从授权服务器获取新的访问令牌。 :ID = XXXX.V2_Json.Translate.XXXXXXX"
$


这不是有效的JSON / javascript。是否可以将异常作为一个有效的JSON对象发送到oncomplete js函数,将异常指示为错误?

context: a front-end application making calls to the microsoft translator api using javascript.

while successful api calls are returned to the oncomplete js function without issue, exception messages are returned as invalid JSONs/js, and as a result, cannot be interpreted; at least, i haven’t found a way to interpret the invalid JSON/js yet.

the header response of both a successful and unsuccessful api call is application/x-javascript; charset=utf-8, yet the content of the unsuccessful api call, which is an exception message, is not valid application/x-javascript. for example here’s one type of exception message returned:

"ArgumentException: The incoming token has expired. Get a new access token from the Authorization Server. : ID=XXXX.V2_Json.Translate.XXXXXXX"

this is not valid JSON/javascript. is it possible to send the exception to the oncomplete js function as a valid JSON object indicating the exception as an error?

推荐答案

关于是否有任何想法是否可能发生这种情况?
any ideas yet on whether or not this might happen?


这篇关于异常消息可以作为有效的JSON返回吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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