Skip to content

Commit

Permalink
Derive the RateLimitExcepton from ChatException
Browse files Browse the repository at this point in the history
  • Loading branch information
penguineer committed Nov 5, 2024
1 parent 28d6179 commit 6c011ce
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpResponse;
import com.penguineering.hareairis.model.ChatException;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -12,11 +13,11 @@
/**
* Exception thrown when the OpenAI service returns a rate limiting error.
*/
public class RateLimitException extends RuntimeException {
public class RateLimitException extends ChatException {
/**
* Creates a RateLimitException from the specified HttpResponse.
*
* @param response The HttpResponse to create the exception from.
* @param response The HttpResponse to create the exception from.
* @param logConsumer The consumer to log any parsing errors.
* @return The RateLimitException created from the HttpResponse.
* @throws IllegalArgumentException If the response status code is not 429.
Expand Down Expand Up @@ -58,8 +59,7 @@ public static RateLimitException fromHttpResponse(HttpResponse response, Consume
* @param message The detail message.
*/
public RateLimitException(String message) {
super(message);
this.retryAfter = null;
this(message, (Instant) null);
}

/**
Expand All @@ -69,7 +69,7 @@ public RateLimitException(String message) {
* @param retryAfter The optional point in time to hint when the service can be called again.
*/
public RateLimitException(String message, Instant retryAfter) {
super(message);
super(Code.CODE_TOO_MANY_REQUESTS, message);
this.retryAfter = retryAfter;
}

Expand All @@ -80,8 +80,7 @@ public RateLimitException(String message, Instant retryAfter) {
* @param duration The duration after which the service can be called again.
*/
public RateLimitException(String message, Duration duration) {
super(message);
this.retryAfter = Instant.now().plus(duration);
this(message, Instant.now().plus(duration));
}

/**
Expand Down

0 comments on commit 6c011ce

Please sign in to comment.