• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk-gen / #49

03 Apr 2025 04:39PM UTC coverage: 35.192% (-25.4%) from 60.563%
#49

push

github

web-flow
fix: Fix handling responses with invalid `json` (box/box-codegen#693) (#264)

39 of 44 new or added lines in 4 files covered. (88.64%)

33 existing lines in 7 files now uncovered.

15240 of 43305 relevant lines covered (35.19%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
/src/main/java/com/box/sdkgen/box/errors/ResponseInfo.java
1
package com.box.sdkgen.box.errors;
2

3
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
4
import com.fasterxml.jackson.databind.JsonNode;
5
import java.util.Map;
6

7
public class ResponseInfo {
8

9
  public final int statusCode;
10

11
  public final Map<String, String> headers;
12

13
  public JsonNode body;
14

15
  public String rawBody;
16

17
  public String code;
18

19
  public JsonNode contextInfo;
20

21
  public String requestId;
22

23
  public String helpUrl;
24

UNCOV
25
  public ResponseInfo(int statusCode, Map<String, String> headers) {
×
UNCOV
26
    this.statusCode = statusCode;
×
UNCOV
27
    this.headers = headers;
×
UNCOV
28
  }
×
29

30
  protected ResponseInfo(ResponseInfoBuilder builder) {
1✔
31
    this.statusCode = builder.statusCode;
1✔
32
    this.headers = builder.headers;
1✔
33
    this.body = builder.body;
1✔
34
    this.rawBody = builder.rawBody;
1✔
35
    this.code = builder.code;
1✔
36
    this.contextInfo = builder.contextInfo;
1✔
37
    this.requestId = builder.requestId;
1✔
38
    this.helpUrl = builder.helpUrl;
1✔
39
  }
1✔
40

41
  public int getStatusCode() {
42
    return statusCode;
1✔
43
  }
44

45
  public Map<String, String> getHeaders() {
46
    return headers;
×
47
  }
48

49
  public JsonNode getBody() {
50
    return body;
1✔
51
  }
52

53
  public String getRawBody() {
54
    return rawBody;
×
55
  }
56

57
  public String getCode() {
58
    return code;
×
59
  }
60

61
  public JsonNode getContextInfo() {
62
    return contextInfo;
×
63
  }
64

65
  public String getRequestId() {
66
    return requestId;
×
67
  }
68

69
  public String getHelpUrl() {
70
    return helpUrl;
×
71
  }
72

73
  public static class ResponseInfoBuilder {
74

75
    protected final int statusCode;
76

77
    protected final Map<String, String> headers;
78

79
    protected JsonNode body;
80

81
    protected String rawBody;
82

83
    protected String code;
84

85
    protected JsonNode contextInfo;
86

87
    protected String requestId;
88

89
    protected String helpUrl;
90

91
    public ResponseInfoBuilder(int statusCode, Map<String, String> headers) {
1✔
92
      this.statusCode = statusCode;
1✔
93
      this.headers = headers;
1✔
94
    }
1✔
95

96
    public ResponseInfoBuilder body(JsonNode body) {
97
      this.body = body;
1✔
98
      return this;
1✔
99
    }
100

101
    public ResponseInfoBuilder rawBody(String rawBody) {
102
      this.rawBody = rawBody;
1✔
103
      return this;
1✔
104
    }
105

106
    public ResponseInfoBuilder code(String code) {
107
      this.code = code;
1✔
108
      return this;
1✔
109
    }
110

111
    public ResponseInfoBuilder contextInfo(JsonNode contextInfo) {
112
      this.contextInfo = contextInfo;
1✔
113
      return this;
1✔
114
    }
115

116
    public ResponseInfoBuilder requestId(String requestId) {
117
      this.requestId = requestId;
1✔
118
      return this;
1✔
119
    }
120

121
    public ResponseInfoBuilder helpUrl(String helpUrl) {
122
      this.helpUrl = helpUrl;
1✔
123
      return this;
1✔
124
    }
125

126
    public ResponseInfo build() {
127
      return new ResponseInfo(this);
1✔
128
    }
129
  }
130

131
  public static ResponseInfo fromResponse(FetchResponse fetchResponse, String rawResponseBody) {
132
    ResponseInfoBuilder builder =
1✔
133
        new ResponseInfoBuilder(fetchResponse.getStatus(), fetchResponse.getHeaders());
1✔
134
    JsonNode body = fetchResponse.getData();
1✔
135
    if (body == null) {
1✔
136
      builder.rawBody(rawResponseBody);
1✔
137
    } else {
138
      builder
1✔
139
          .body(body)
1✔
140
          .rawBody(body.toString())
1✔
141
          .code(body.get("code") != null ? body.get("code").asText("") : null)
1✔
142
          .contextInfo(body.get("context_info") != null ? body.get("context_info") : null)
1✔
143
          .requestId(body.get("request_id") != null ? body.get("request_id").asText() : null)
1✔
144
          .helpUrl(body.get("help_url") != null ? body.get("help_url").asText() : null);
1✔
145
    }
146

147
    return builder.build();
1✔
148
  }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc