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

box / box-java-sdk / #7064

15 May 2026 10:50AM UTC coverage: 35.007% (+0.07%) from 34.935%
#7064

push

github

web-flow
feat: Sanitize request body in `BoxAPIError` (box/box-codegen#948) (#1844)

8 of 41 new or added lines in 5 files covered. (19.51%)

43 existing lines in 7 files now uncovered.

19372 of 55338 relevant lines covered (35.01%)

0.35 hits per line

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

62.79
/src/main/java/com/box/sdkgen/box/errors/BoxAPIError.java
1
package com.box.sdkgen.box.errors;
2

3
import com.box.sdkgen.internal.logging.DataSanitizer;
4
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
5
import com.fasterxml.jackson.databind.JsonNode;
6
import java.time.LocalDateTime;
7
import java.util.Optional;
8
import okhttp3.Request;
9

10
public class BoxAPIError extends BoxSDKError {
11

12
  public final RequestInfo requestInfo;
13

14
  public final ResponseInfo responseInfo;
15

16
  private final DataSanitizer dataSanitizer;
17

18
  public BoxAPIError(String message, RequestInfo requestInfo, ResponseInfo responseInfo) {
19
    super(message);
×
20
    this.requestInfo = requestInfo;
×
21
    this.responseInfo = responseInfo;
×
22
    this.dataSanitizer = new DataSanitizer();
×
23
  }
×
24

25
  public static BoxAPIError fromAPICall(
26
      Request request,
27
      FetchResponse fetchResponse,
28
      String rawResponseBody,
29
      DataSanitizer dataSanitizer) {
NEW
30
    return fromAPICall(request, fetchResponse, rawResponseBody, dataSanitizer, null);
×
31
  }
32

33
  public static BoxAPIError fromAPICall(
34
      Request request,
35
      FetchResponse fetchResponse,
36
      String rawResponseBody,
37
      DataSanitizer dataSanitizer,
38
      String contentType) {
39
    RequestInfo requestInfo = RequestInfo.fromRequest(request, contentType);
1✔
40
    ResponseInfo responseInfo = ResponseInfo.fromResponse(fetchResponse, rawResponseBody);
1✔
41

42
    String requestId =
1✔
43
        Optional.ofNullable(responseInfo.getBody())
1✔
44
            .map(body -> body.get("request_id"))
1✔
45
            .map(JsonNode::asText)
1✔
46
            .orElse("");
1✔
47

48
    return new Builder(
1✔
49
            String.format("Status %d; Request ID: %s", responseInfo.getStatusCode(), requestId),
1✔
50
            requestInfo,
51
            responseInfo)
52
        .timestamp(LocalDateTime.now().toString())
1✔
53
        .dataSanitizer(dataSanitizer)
1✔
54
        .build();
1✔
55
  }
56

57
  protected BoxAPIError(Builder builder) {
58
    super(builder);
1✔
59
    this.requestInfo = builder.requestInfo;
1✔
60
    this.responseInfo = builder.responseInfo;
1✔
61
    this.dataSanitizer = builder.dataSanitizer;
1✔
62
  }
1✔
63

64
  public RequestInfo getRequestInfo() {
UNCOV
65
    return requestInfo;
×
66
  }
67

68
  public ResponseInfo getResponseInfo() {
UNCOV
69
    return responseInfo;
×
70
  }
71

72
  public static class Builder extends BoxSDKError.Builder {
73

74
    protected final RequestInfo requestInfo;
75

76
    protected final ResponseInfo responseInfo;
77

78
    protected DataSanitizer dataSanitizer;
79

80
    public Builder(String message, RequestInfo requestInfo, ResponseInfo responseInfo) {
81
      super(message);
1✔
82
      this.requestInfo = requestInfo;
1✔
83
      this.responseInfo = responseInfo;
1✔
84
      this.dataSanitizer = new DataSanitizer();
1✔
85
    }
1✔
86

87
    @Override
88
    public Builder timestamp(String timestamp) {
89
      this.timestamp = timestamp;
1✔
90
      return this;
1✔
91
    }
92

93
    @Override
94
    public Builder error(Exception error) {
UNCOV
95
      this.error = error;
×
UNCOV
96
      return this;
×
97
    }
98

99
    @Override
100
    public Builder name(String name) {
UNCOV
101
      this.name = name;
×
UNCOV
102
      return this;
×
103
    }
104

105
    public Builder dataSanitizer(DataSanitizer dataSanitizer) {
106
      this.dataSanitizer = dataSanitizer;
1✔
107
      return this;
1✔
108
    }
109

110
    public BoxAPIError build() {
111
      return new BoxAPIError(this);
1✔
112
    }
113
  }
114

115
  @Override
116
  public String toString() {
UNCOV
117
    return String.join(
×
118
        "",
UNCOV
119
        super.toString(),
×
UNCOV
120
        String.format("\nRequest: %s", requestInfo.print(dataSanitizer)),
×
UNCOV
121
        String.format("\nResponse: %s", responseInfo.print(dataSanitizer)));
×
122
  }
123
}
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