Skip to content

Commit 641585d

Browse files
authored
Added ApiException as a cause to mapHttpStatusError (#127)
## Problem When the request fails before sending a request / receiving an HTTP response, the exception cause is ignored, and the client returns an empty error message: ``` Caused by: io.pinecone.exceptions.PineconeUnmappedHttpException: null at io.pinecone.exceptions.HttpErrorMapper.mapHttpStatusError(HttpErrorMapper.java:21) at io.pinecone.clients.Pinecone.handleApiException(Pinecone.java:794) at io.pinecone.clients.Pinecone.describeIndex(Pinecone.java:441) ``` ## Solution Added the apiException as the cause HttpErrorMapper.mapHttpStatusError to make debugging easier. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan not required
1 parent 759c324 commit 641585d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/main/java/io/pinecone/clients/Pinecone.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ private void handleApiException(ApiException apiException) throws PineconeExcept
791791
int statusCode = apiException.getCode();
792792
String responseBody = apiException.getResponseBody();
793793
FailedRequestInfo failedRequestInfo = new FailedRequestInfo(statusCode, responseBody);
794-
HttpErrorMapper.mapHttpStatusError(failedRequestInfo);
794+
HttpErrorMapper.mapHttpStatusError(failedRequestInfo, apiException);
795795
}
796796

797797

Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package io.pinecone.exceptions;
22

3+
import org.openapitools.client.ApiException;
4+
35
public class HttpErrorMapper {
46

5-
public static void mapHttpStatusError(FailedRequestInfo failedRequestInfo) throws PineconeException {
7+
public static void mapHttpStatusError(FailedRequestInfo failedRequestInfo,
8+
ApiException apiException) throws PineconeException {
69
int statusCode = failedRequestInfo.getStatus();
710
switch (statusCode) {
811
case 400:
9-
throw new PineconeBadRequestException(failedRequestInfo.getMessage());
12+
throw new PineconeBadRequestException(failedRequestInfo.getMessage(), apiException);
1013
case 401:
11-
throw new PineconeAuthorizationException(failedRequestInfo.getMessage());
14+
throw new PineconeAuthorizationException(failedRequestInfo.getMessage(), apiException);
1215
case 403:
13-
throw new PineconeForbiddenException(failedRequestInfo.getMessage());
16+
throw new PineconeForbiddenException(failedRequestInfo.getMessage(), apiException);
1417
case 404:
15-
throw new PineconeNotFoundException(failedRequestInfo.getMessage());
18+
throw new PineconeNotFoundException(failedRequestInfo.getMessage(), apiException);
1619
case 409:
17-
throw new PineconeAlreadyExistsException(failedRequestInfo.getMessage());
20+
throw new PineconeAlreadyExistsException(failedRequestInfo.getMessage(), apiException);
1821
case 500:
19-
throw new PineconeInternalServerException(failedRequestInfo.getMessage());
22+
throw new PineconeInternalServerException(failedRequestInfo.getMessage(), apiException);
2023
default:
21-
throw new PineconeUnmappedHttpException(failedRequestInfo.getMessage());
24+
throw new PineconeUnmappedHttpException(failedRequestInfo.getMessage(), apiException);
2225
}
2326
}
2427
}

0 commit comments

Comments
 (0)