Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 改装。如果(!response.issueccessful())获取响应_Java_Android_Error Handling_Retrofit_Retrofit2 - Fatal编程技术网

Java 改装。如果(!response.issueccessful())获取响应

Java 改装。如果(!response.issueccessful())获取响应,java,android,error-handling,retrofit,retrofit2,Java,Android,Error Handling,Retrofit,Retrofit2,在新的改型中,我将调用并覆盖响应和失败两种方法 如果改型成功地解析了对我的类模型的响应,我可以让它变得简单 但是如果(!response.issueccessful()),如何获取服务器响应 我看到了代码错误。原始响应。错误主体。但未看到来自服务器的响应。 这是我的服务器错误。。。如何从回应中得到它 { "message": "422 Unprocessable Entity", "errors": { "lang": [

在新的改型中,我将调用并覆盖响应和失败两种方法

如果改型成功地解析了对我的类模型的响应,我可以让它变得简单 但是如果(!response.issueccessful()),如何获取服务器响应

我看到了代码错误。原始响应。错误主体。但未看到来自服务器的响应。 这是我的服务器错误。。。如何从回应中得到它

        {  
 "message": "422 Unprocessable Entity", 
  "errors": {
            "lang": [
              "Lang required."
            ],
            "provider": [
              "Provider required."
            ] 
      },  
         "status_code": 422 }

使用此选项可以获得错误主体

  if (response != null && response.errorBody() != null) {
    JSONObject jsonObject = new JSONObject(response.errorBody().string());
    String message = jsonObject.getString("message");
    String errors =  jsonObject.getString("errors");
  }

这就是我需要的->response.errorBody().string()