Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 540ae2e

Browse files
author
deep-learning-dynamo
committed
Now using OpenAiHttpException instead of RuntimeException
1 parent 76cd0f6 commit 540ae2e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dev.ai4j.openai4j;
2+
3+
public class OpenAiHttpException extends RuntimeException {
4+
5+
private final int code;
6+
7+
public OpenAiHttpException(int code, String message) {
8+
super(message);
9+
this.code = code;
10+
}
11+
12+
public int code() {
13+
return code;
14+
}
15+
}

src/main/java/dev/ai4j/openai4j/Utils.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55
class Utils {
66

77
static RuntimeException toException(retrofit2.Response<?> response) throws IOException {
8-
9-
int code = response.code();
10-
String body = response.errorBody().string();
11-
12-
String errorMessage = String.format("status code: %s; body: %s", code, body);
13-
return new RuntimeException(errorMessage);
8+
return new OpenAiHttpException(response.code(), response.errorBody().string());
149
}
1510

1611
static RuntimeException toException(okhttp3.Response response) throws IOException {
17-
18-
int code = response.code();
19-
String body = response.body().string();
20-
21-
String errorMessage = String.format("status code: %s; body: %s", code, body);
22-
return new RuntimeException(errorMessage);
12+
return new OpenAiHttpException(response.code(), response.body().string());
2313
}
2414
}

0 commit comments

Comments
 (0)