Return JSON with error status code MVC

前端 未结 11 1769
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 13:23

I was trying to return an error to the call to the controller as advised in This link so that client can take appropriate action. The controller is called by javascript via

11条回答
  •  伪装坚强ぢ
    2020-11-27 13:57

    You need to decide if you want "HTTP level error" (that what error codes are for) or "application level error" (that what your custom JSON response is for).

    Most high level objects using HTTP will never look into response stream if error code set to something that is not 2xx (success range). In your case you are explicitly setting error code to failure (I think 403 or 500) and force XMLHttp object to ignore body of the response.

    To fix - either handle error conditions on client side or not set error code and return JSON with error information (see Sbossb reply for details).

提交回复
热议问题