|
3 | 3 |
|
4 | 4 | package com.azure.ai.agents.implementation.http; |
5 | 5 |
|
6 | | -import com.azure.core.exception.ClientAuthenticationException; |
7 | 6 | import com.azure.core.exception.HttpResponseException; |
8 | | -import com.azure.core.exception.ResourceNotFoundException; |
9 | 7 | import com.azure.core.http.HttpHeaderName; |
10 | 8 | import com.azure.core.http.HttpHeaders; |
11 | 9 | import com.azure.core.http.HttpMethod; |
@@ -126,29 +124,48 @@ public CompletableFuture<HttpResponse> executeAsync(HttpRequest request, Request |
126 | 124 | * @return The corresponding OpenAI exception. |
127 | 125 | */ |
128 | 126 | private static Throwable mapAzureExceptionToOpenAI(Throwable throwable) { |
129 | | - if (throwable instanceof HttpResponseException httpResponseException) { |
| 127 | + if (throwable instanceof HttpResponseException) { |
| 128 | + HttpResponseException httpResponseException = (HttpResponseException) throwable; |
130 | 129 | int statusCode = httpResponseException.getResponse().getStatusCode(); |
131 | 130 | Headers headers = toOpenAIHeaders(httpResponseException.getResponse().getHeaders()); |
132 | 131 | Throwable cause = httpResponseException.getCause(); |
133 | 132 |
|
134 | | - return switch (statusCode) { |
135 | | - case 400 -> BadRequestException.builder().headers(headers).cause(cause).build(); |
136 | | - case 401 -> UnauthorizedException.builder().headers(headers).cause(cause).build(); |
137 | | - case 403 -> PermissionDeniedException.builder().headers(headers).cause(cause).build(); |
138 | | - case 404 -> NotFoundException.builder().headers(headers).cause(cause).build(); |
139 | | - case 422 -> UnprocessableEntityException.builder().headers(headers).cause(cause).build(); |
140 | | - case 429 -> RateLimitException.builder().headers(headers).cause(cause).build(); |
141 | | - case 500, 502, 503, 504 -> InternalServerException.builder() |
142 | | - .statusCode(statusCode) |
143 | | - .headers(headers) |
144 | | - .cause(cause) |
145 | | - .build(); |
146 | | - default -> UnexpectedStatusCodeException.builder() |
147 | | - .statusCode(statusCode) |
148 | | - .headers(headers) |
149 | | - .cause(cause) |
150 | | - .build(); |
151 | | - }; |
| 133 | + switch (statusCode) { |
| 134 | + case 400: |
| 135 | + return BadRequestException.builder().headers(headers).cause(cause).build(); |
| 136 | + |
| 137 | + case 401: |
| 138 | + return UnauthorizedException.builder().headers(headers).cause(cause).build(); |
| 139 | + |
| 140 | + case 403: |
| 141 | + return PermissionDeniedException.builder().headers(headers).cause(cause).build(); |
| 142 | + |
| 143 | + case 404: |
| 144 | + return NotFoundException.builder().headers(headers).cause(cause).build(); |
| 145 | + |
| 146 | + case 422: |
| 147 | + return UnprocessableEntityException.builder().headers(headers).cause(cause).build(); |
| 148 | + |
| 149 | + case 429: |
| 150 | + return RateLimitException.builder().headers(headers).cause(cause).build(); |
| 151 | + |
| 152 | + case 500: |
| 153 | + case 502: |
| 154 | + case 503: |
| 155 | + case 504: |
| 156 | + return InternalServerException.builder() |
| 157 | + .statusCode(statusCode) |
| 158 | + .headers(headers) |
| 159 | + .cause(cause) |
| 160 | + .build(); |
| 161 | + |
| 162 | + default: |
| 163 | + return UnexpectedStatusCodeException.builder() |
| 164 | + .statusCode(statusCode) |
| 165 | + .headers(headers) |
| 166 | + .cause(cause) |
| 167 | + .build(); |
| 168 | + } |
152 | 169 | } else { |
153 | 170 | return new OpenAIException(throwable.getMessage(), throwable.getCause()); |
154 | 171 | } |
|
0 commit comments