File tree Expand file tree Collapse file tree 5 files changed +47
-8
lines changed
foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai
main/java/com/sap/ai/sdk/orchestration
java/com/sap/ai/sdk/orchestration Expand file tree Collapse file tree 5 files changed +47
-8
lines changed Original file line number Diff line number Diff line change 88import lombok .AccessLevel ;
99import lombok .AllArgsConstructor ;
1010import lombok .Value ;
11- import lombok .experimental .Delegate ;
1211
1312/**
1413 * Represents an error response from the OpenAI API.
2019@ AllArgsConstructor (onConstructor = @ __ ({@ JsonCreator }), access = AccessLevel .PROTECTED )
2120public class OpenAiError implements ClientError {
2221 /** The original error response from the OpenAI API. */
23- @ Delegate (types = {ClientError .class })
2422 ErrorResponse originalResponse ;
2523
2624 /**
Original file line number Diff line number Diff line change 3434 <coverage .complexity>82%</coverage .complexity>
3535 <coverage .line>93%</coverage .line>
3636 <coverage .instruction>94%</coverage .instruction>
37- <coverage .branch>76 %</coverage .branch>
37+ <coverage .branch>75 %</coverage .branch>
3838 <coverage .method>93%</coverage .method>
3939 <coverage .class>100%</coverage .class>
4040 </properties >
Original file line number Diff line number Diff line change 44import com .google .common .annotations .Beta ;
55import com .sap .ai .sdk .core .common .ClientError ;
66import com .sap .ai .sdk .orchestration .model .ErrorResponse ;
7+ import javax .annotation .Nonnull ;
78import lombok .AccessLevel ;
89import lombok .AllArgsConstructor ;
910import lombok .Value ;
10- import lombok .experimental .Delegate ;
1111
1212/**
1313 * Orchestration error response.
1818@ Value
1919@ Beta
2020public class OrchestrationError implements ClientError {
21- @ Delegate (types = {ClientError .class })
2221 ErrorResponse originalResponse ;
22+
23+ /**
24+ * Gets the error message from the contained original response.
25+ *
26+ * @return the error message
27+ */
28+ @ Nonnull
29+ public String getMessage () {
30+ return originalResponse .getCode () == 500
31+ ? originalResponse .getMessage () + " located in " + originalResponse .getLocation ()
32+ : originalResponse .getMessage ();
33+ }
2334}
Original file line number Diff line number Diff line change @@ -126,6 +126,21 @@ void testCompletion() {
126126 assertThat (result .getContent ()).isNotEmpty ();
127127 }
128128
129+ @ Test
130+ void testCompletionError () {
131+ stubFor (
132+ post (urlPathEqualTo ("/completion" ))
133+ .willReturn (
134+ aResponse ()
135+ .withStatus (500 )
136+ .withBodyFile ("error500Response.json" )
137+ .withHeader ("Content-Type" , "application/json" )));
138+
139+ assertThatThrownBy (() -> client .chatCompletion (prompt , config ))
140+ .hasMessage (
141+ "Request failed with status 500 Server Error and error message: 'Internal Server Error located in Masking Module - Masking'" );
142+ }
143+
129144 @ Test
130145 void testGrounding () throws IOException {
131146 stubFor (
@@ -185,9 +200,10 @@ void testGrounding() throws IOException {
185200 "First chunk```Second chunk```Last found chunk" );
186201 assertThat (groundingModule .getData ()).isEqualTo (groundingData );
187202
188- final String requestBody = new String (fileLoader .apply ("groundingRequest.json" ).readAllBytes ());
189- verify (
190- postRequestedFor (urlPathEqualTo ("/completion" )).withRequestBody (equalToJson (requestBody )));
203+ try (var requestInputStream = fileLoader .apply ("groundingRequest.json" )) {
204+ final String request = new String (requestInputStream .readAllBytes ());
205+ verify (postRequestedFor (urlPathEqualTo ("/completion" )).withRequestBody (equalToJson (request )));
206+ }
191207 }
192208
193209 @ Test
Original file line number Diff line number Diff line change 1+ {
2+ "request_id" : " d647775b-725b-428a-90b7-348cbf30f7f4" ,
3+ "code" : 500 ,
4+ "message" : " Internal Server Error" ,
5+ "location" : " Masking Module - Masking" ,
6+ "module_results" : {
7+ "templating" : [
8+ {
9+ "role" : " user" ,
10+ "content" : " yo"
11+ }
12+ ]
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments