-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathSapApiException.java
More file actions
68 lines (60 loc) · 2.38 KB
/
Copy pathSapApiException.java
File metadata and controls
68 lines (60 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.keploy.sapdemo.customer360.sap;
import org.springframework.http.HttpStatus;
/**
* Application-level exception that translates SAP-side failures into something
* the Spring MVC layer can map to a meaningful HTTP status.
*
* <p>Thrown by the {@link SapBusinessPartnerClient} when:
* <ul>
* <li>SAP returns a 4xx/5xx response (status preserved verbatim)</li>
* <li>A transport-level error occurs (connect timeout, read timeout,
* TLS failure — mapped to 502 Bad Gateway)</li>
* <li>A response body cannot be deserialised to the expected model
* (mapped to 502 Bad Gateway with a schema-drift hint)</li>
* </ul>
*
* <p>The {@link #upstreamStatus} field preserves the exact status SAP returned
* so {@link com.keploy.sapdemo.customer360.web.GlobalExceptionHandler}
* can surface it in an RFC 7807 problem response as
* {@code X-Upstream-Status}. Keploy captures this header verbatim in the
* replayed mocks, which lets contract-diff checks catch status regressions
* even when the body hasn't changed.
*/
public class SapApiException extends RuntimeException {
private final HttpStatus upstreamStatus;
private final String sapErrorCode;
/**
* Minimal constructor — upstream HTTP status + message only.
* Use this for SAP-returned 4xx/5xx errors where no further code or
* underlying cause is available.
*/
public SapApiException(HttpStatus upstreamStatus, String message) {
super(message);
this.upstreamStatus = upstreamStatus;
this.sapErrorCode = null;
}
/**
* With SAP error code (from the OData error envelope, e.g.
* {@code "error.code": "SY/530"}) for richer client diagnostics.
*/
public SapApiException(HttpStatus upstreamStatus, String sapErrorCode, String message) {
super(message);
this.upstreamStatus = upstreamStatus;
this.sapErrorCode = sapErrorCode;
}
/**
* For transport-level failures that wrap an underlying cause
* (IOException, deserialisation failure, etc.).
*/
public SapApiException(HttpStatus upstreamStatus, String message, Throwable cause) {
super(message, cause);
this.upstreamStatus = upstreamStatus;
this.sapErrorCode = null;
}
public HttpStatus getUpstreamStatus() {
return upstreamStatus;
}
public String getSapErrorCode() {
return sapErrorCode;
}
}