-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: introduce Store(Item)?NotFoundException
classes
#360
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ff0e6f
refactor: introduce `Store(Item)?NotFoundException` classes
malandis f248916
chore: style tweak
malandis 5b26105
refactor: already exists exception on create store
malandis 605a3e4
refactor: read error details from metadata
malandis 7b8fbf3
fix: remove `metadata` argument when calling exc mapper.convert
malandis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,18 @@ public static SdkException convert(Throwable e, Metadata metadata) { | |
if (e instanceof io.grpc.StatusRuntimeException) { | ||
final StatusRuntimeException grpcException = (StatusRuntimeException) e; | ||
final Status.Code statusCode = grpcException.getStatus().getCode(); | ||
final Metadata trailers = grpcException.getTrailers(); | ||
|
||
final MomentoTransportErrorDetails errorDetails = | ||
new MomentoTransportErrorDetails( | ||
new MomentoGrpcErrorDetails(statusCode, grpcException.getMessage(), metadata)); | ||
|
||
String errorCause = trailers.get(Metadata.Key.of("err", Metadata.ASCII_STRING_MARSHALLER)); | ||
if (errorCause == null) { | ||
// TODO remove once control service is updated to send "err" in metadata | ||
errorCause = grpcException.getMessage(); | ||
} | ||
|
||
switch (statusCode) { | ||
case INVALID_ARGUMENT: | ||
// fall through | ||
|
@@ -75,8 +82,14 @@ public static SdkException convert(Throwable e, Metadata metadata) { | |
return new LimitExceededException(grpcException, errorDetails); | ||
|
||
case NOT_FOUND: | ||
return new NotFoundException(grpcException, errorDetails); | ||
|
||
if (errorCause.contains("element_not_found")) { | ||
return new StoreItemNotFoundException(grpcException, errorDetails); | ||
// TODO change once control service is updated to send "Store with name" in metadata | ||
} else if (errorCause.contains("Store with name")) { | ||
return new StoreNotFoundException(grpcException, errorDetails); | ||
} else { | ||
return new NotFoundException(grpcException, errorDetails); | ||
} | ||
Comment on lines
+85
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update these once the server is up to date. |
||
case ALREADY_EXISTS: | ||
return new AlreadyExistsException(grpcException, errorDetails); | ||
|
||
|
34 changes: 34 additions & 0 deletions
34
momento-sdk/src/main/java/momento/sdk/exceptions/StoreItemNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package momento.sdk.exceptions; | ||
|
||
import momento.sdk.internal.MomentoTransportErrorDetails; | ||
|
||
/** The item requested from the store doesn't exist. */ | ||
public class StoreItemNotFoundException extends SdkException { | ||
|
||
private static final String MESSAGE = | ||
"The item requested from the store does not exist. To resolve this error, " | ||
+ "if the requested item was expected to be found, put it in the store."; | ||
|
||
/** | ||
* Constructs a StoreItemNotFound with a cause and error details. | ||
* | ||
* @param cause the cause. | ||
* @param transportErrorDetails details about the request and error. | ||
*/ | ||
public StoreItemNotFoundException( | ||
Throwable cause, MomentoTransportErrorDetails transportErrorDetails) { | ||
super( | ||
MomentoErrorCode.NOT_FOUND_ERROR, | ||
completeMessage(transportErrorDetails), | ||
cause, | ||
transportErrorDetails); | ||
} | ||
|
||
private static String completeMessage(MomentoTransportErrorDetails transportErrorDetails) { | ||
return transportErrorDetails | ||
.getGrpcErrorDetails() | ||
.getCacheName() | ||
.map(s -> MESSAGE + " Store name: " + s) | ||
.orElse(MESSAGE); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
momento-sdk/src/main/java/momento/sdk/exceptions/StoreNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package momento.sdk.exceptions; | ||
|
||
import momento.sdk.internal.MomentoTransportErrorDetails; | ||
|
||
/** The store requested doesn't exist. */ | ||
public class StoreNotFoundException extends MomentoServiceException { | ||
|
||
private static final String MESSAGE = | ||
"A store with the specified name does not exist. To resolve this error, " | ||
+ "make sure you have created the store before attempting to use it."; | ||
|
||
/** | ||
* Constructs a StoreNotFoundException with a cause and error details. | ||
* | ||
* @param cause the cause. | ||
* @param transportErrorDetails details about the request and error. | ||
*/ | ||
public StoreNotFoundException( | ||
Throwable cause, MomentoTransportErrorDetails transportErrorDetails) { | ||
super( | ||
MomentoErrorCode.NOT_FOUND_ERROR, | ||
completeMessage(transportErrorDetails), | ||
cause, | ||
transportErrorDetails); | ||
} | ||
|
||
private static String completeMessage(MomentoTransportErrorDetails transportErrorDetails) { | ||
return transportErrorDetails | ||
.getGrpcErrorDetails() | ||
.getCacheName() | ||
.map(s -> MESSAGE + " Store name: " + s) | ||
.orElse(MESSAGE); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update this once the server is up to date.