diff --git a/examples/MomentoApplication/MomentoApplication.csproj b/examples/MomentoApplication/MomentoApplication.csproj
index 4b042904..3db91ed6 100644
--- a/examples/MomentoApplication/MomentoApplication.csproj
+++ b/examples/MomentoApplication/MomentoApplication.csproj
@@ -7,6 +7,7 @@
-
+
+
diff --git a/src/Momento.Sdk/Exceptions/AlreadyExistsException.cs b/src/Momento.Sdk/Exceptions/AlreadyExistsException.cs
index f1b80aa4..ca63cf0c 100644
--- a/src/Momento.Sdk/Exceptions/AlreadyExistsException.cs
+++ b/src/Momento.Sdk/Exceptions/AlreadyExistsException.cs
@@ -5,7 +5,10 @@
///
public class AlreadyExistsException : SdkException
{
- public AlreadyExistsException(string message) : base(message)
+ public AlreadyExistsException(string message) : base(message, MomentoErrorCode.ALREADY_EXISTS_ERROR)
+ {
+ }
+ public AlreadyExistsException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.ALREADY_EXISTS_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/AuthenticationException.cs b/src/Momento.Sdk/Exceptions/AuthenticationException.cs
index 53ef3112..d8c1a0af 100644
--- a/src/Momento.Sdk/Exceptions/AuthenticationException.cs
+++ b/src/Momento.Sdk/Exceptions/AuthenticationException.cs
@@ -5,7 +5,10 @@
///
public class AuthenticationException : SdkException
{
- public AuthenticationException(string message) : base(message)
+ public AuthenticationException(string message) : base(message, MomentoErrorCode.AUTHENTICATION_ERROR)
+ {
+ }
+ public AuthenticationException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.AUTHENTICATION_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/BadRequestException.cs b/src/Momento.Sdk/Exceptions/BadRequestException.cs
index 61823e6d..86981dc1 100644
--- a/src/Momento.Sdk/Exceptions/BadRequestException.cs
+++ b/src/Momento.Sdk/Exceptions/BadRequestException.cs
@@ -5,7 +5,10 @@
///
public class BadRequestException : SdkException
{
- public BadRequestException(string message) : base(message)
+ public BadRequestException(string message) : base(message, MomentoErrorCode.BAD_REQUEST_ERROR)
+ {
+ }
+ public BadRequestException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.BAD_REQUEST_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/CacheExceptionMapper.cs b/src/Momento.Sdk/Exceptions/CacheExceptionMapper.cs
index 95a89397..c1fb472f 100644
--- a/src/Momento.Sdk/Exceptions/CacheExceptionMapper.cs
+++ b/src/Momento.Sdk/Exceptions/CacheExceptionMapper.cs
@@ -16,42 +16,46 @@ public static Exception Convert(Exception e)
}
if (e is RpcException ex)
{
+ MomentoErrorTransportDetails transportDetails = new MomentoErrorTransportDetails(
+ new MomentoGrpcErrorDetails(ex.StatusCode, ex.Message, null)
+ );
+
switch (ex.StatusCode)
{
case StatusCode.InvalidArgument:
case StatusCode.OutOfRange:
case StatusCode.Unimplemented:
- return new BadRequestException(ex.Message);
+ return new BadRequestException(ex.Message, transportDetails);
case StatusCode.FailedPrecondition:
- return new FailedPreconditionException(ex.Message);
+ return new FailedPreconditionException(ex.Message, transportDetails);
case StatusCode.PermissionDenied:
- return new PermissionDeniedException(ex.Message);
+ return new PermissionDeniedException(ex.Message, transportDetails);
case StatusCode.Unauthenticated:
- return new AuthenticationException(ex.Message);
+ return new AuthenticationException(ex.Message, transportDetails);
case StatusCode.ResourceExhausted:
- return new LimitExceededException(ex.Message);
+ return new LimitExceededException(ex.Message, transportDetails);
case StatusCode.NotFound:
- return new NotFoundException(ex.Message);
+ return new NotFoundException(ex.Message, transportDetails);
case StatusCode.AlreadyExists:
- return new AlreadyExistsException(ex.Message);
+ return new AlreadyExistsException(ex.Message, transportDetails);
case StatusCode.DeadlineExceeded:
- return new TimeoutException(ex.Message);
+ return new TimeoutException(ex.Message, transportDetails);
case StatusCode.Cancelled:
- return new CancelledException(ex.Message);
+ return new CancelledException(ex.Message, transportDetails);
case StatusCode.Unknown:
case StatusCode.Unavailable:
case StatusCode.Aborted:
case StatusCode.DataLoss:
- default: return new InternalServerException(INTERNAL_SERVER_ERROR_MESSAGE, e);
+ default: return new InternalServerException(INTERNAL_SERVER_ERROR_MESSAGE, transportDetails, e);
}
}
return new UnknownException(SDK_ERROR_MESSAGE, e);
diff --git a/src/Momento.Sdk/Exceptions/CancelledException.cs b/src/Momento.Sdk/Exceptions/CancelledException.cs
index 44ff6293..c9b38991 100644
--- a/src/Momento.Sdk/Exceptions/CancelledException.cs
+++ b/src/Momento.Sdk/Exceptions/CancelledException.cs
@@ -5,7 +5,10 @@ public class CancelledException : SdkException
///
/// Operation was cancelled.
///
- public CancelledException(string message) : base(message)
+ public CancelledException(string message) : base(message, MomentoErrorCode.CANCELLED_ERROR)
+ {
+ }
+ public CancelledException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.CANCELLED_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/FailedPreconditionException.cs b/src/Momento.Sdk/Exceptions/FailedPreconditionException.cs
index fe5cdaa1..ad6455a7 100644
--- a/src/Momento.Sdk/Exceptions/FailedPreconditionException.cs
+++ b/src/Momento.Sdk/Exceptions/FailedPreconditionException.cs
@@ -8,7 +8,10 @@ namespace Momento.Sdk.Exceptions;
///
public class FailedPreconditionException : SdkException
{
- public FailedPreconditionException(string message) : base(message)
+ public FailedPreconditionException(string message) : base(message, MomentoErrorCode.FAILED_PRECONDITION_ERROR)
+ {
+ }
+ public FailedPreconditionException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.FAILED_PRECONDITION_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/InternalServerException.cs b/src/Momento.Sdk/Exceptions/InternalServerException.cs
index 6e14f900..c6e8573d 100644
--- a/src/Momento.Sdk/Exceptions/InternalServerException.cs
+++ b/src/Momento.Sdk/Exceptions/InternalServerException.cs
@@ -7,10 +7,13 @@ namespace Momento.Sdk.Exceptions;
///
public class InternalServerException : SdkException
{
- public InternalServerException(string message, Exception e) : base(message, e)
+ public InternalServerException(string message) : base(message, MomentoErrorCode.INTERNAL_SERVER_ERROR)
{
}
- public InternalServerException(string message) : base(message)
+ public InternalServerException(string message, Exception e) : base(message, MomentoErrorCode.INTERNAL_SERVER_ERROR, null, e)
+ {
+ }
+ public InternalServerException(string message, MomentoErrorTransportDetails transportDetails, Exception e) : base(message, MomentoErrorCode.INTERNAL_SERVER_ERROR, transportDetails, e)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/InvalidArgumentException.cs b/src/Momento.Sdk/Exceptions/InvalidArgumentException.cs
index 76122060..b646c95d 100644
--- a/src/Momento.Sdk/Exceptions/InvalidArgumentException.cs
+++ b/src/Momento.Sdk/Exceptions/InvalidArgumentException.cs
@@ -7,11 +7,11 @@ namespace Momento.Sdk.Exceptions;
///
public class InvalidArgumentException : SdkException
{
- public InvalidArgumentException(string message) : base(message)
+ public InvalidArgumentException(string message) : base(message, MomentoErrorCode.INVALID_ARGUMENT_ERROR)
{
}
- public InvalidArgumentException(string message, Exception e) : base(message, e)
+ public InvalidArgumentException(string message, Exception e) : base(message, MomentoErrorCode.INVALID_ARGUMENT_ERROR, null, e)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/LimitExceededException.cs b/src/Momento.Sdk/Exceptions/LimitExceededException.cs
index e18c982c..ff55e94b 100644
--- a/src/Momento.Sdk/Exceptions/LimitExceededException.cs
+++ b/src/Momento.Sdk/Exceptions/LimitExceededException.cs
@@ -5,7 +5,11 @@
///
public class LimitExceededException : SdkException
{
- public LimitExceededException(string message) : base(message)
+ public LimitExceededException(string message) : base(message, MomentoErrorCode.LIMIT_EXCEEDED_ERROR)
{
}
+ public LimitExceededException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.LIMIT_EXCEEDED_ERROR, transportDetails)
+ {
+ this.transportDetails = transportDetails;
+ }
}
diff --git a/src/Momento.Sdk/Exceptions/NotFoundException.cs b/src/Momento.Sdk/Exceptions/NotFoundException.cs
index 560bf0c4..eeb5d003 100644
--- a/src/Momento.Sdk/Exceptions/NotFoundException.cs
+++ b/src/Momento.Sdk/Exceptions/NotFoundException.cs
@@ -5,7 +5,10 @@
///
public class NotFoundException : SdkException
{
- public NotFoundException(string message) : base(message)
+ public NotFoundException(string message) : base(message, MomentoErrorCode.NOT_FOUND_ERROR)
+ {
+ }
+ public NotFoundException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.NOT_FOUND_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/PermissionDeniedException.cs b/src/Momento.Sdk/Exceptions/PermissionDeniedException.cs
index 7da5bcf2..d7402fb8 100644
--- a/src/Momento.Sdk/Exceptions/PermissionDeniedException.cs
+++ b/src/Momento.Sdk/Exceptions/PermissionDeniedException.cs
@@ -5,7 +5,10 @@
///
public class PermissionDeniedException : SdkException
{
- public PermissionDeniedException(string message) : base(message)
+ public PermissionDeniedException(string message) : base(message, MomentoErrorCode.PERMISSION_ERROR)
+ {
+ }
+ public PermissionDeniedException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.PERMISSION_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/SdkException.cs b/src/Momento.Sdk/Exceptions/SdkException.cs
index a4995d0c..ff5eef00 100644
--- a/src/Momento.Sdk/Exceptions/SdkException.cs
+++ b/src/Momento.Sdk/Exceptions/SdkException.cs
@@ -1,13 +1,65 @@
using System;
+using Grpc.Core;
namespace Momento.Sdk.Exceptions;
+public enum MomentoErrorCode {
+ INVALID_ARGUMENT_ERROR,
+ UNKNOWN_SERVICE_ERROR,
+ ALREADY_EXISTS_ERROR,
+ NOT_FOUND_ERROR,
+ INTERNAL_SERVER_ERROR,
+ PERMISSION_ERROR,
+ AUTHENTICATION_ERROR,
+ CANCELLED_ERROR,
+ LIMIT_EXCEEDED_ERROR,
+ BAD_REQUEST_ERROR,
+ TIMEOUT_ERROR,
+ SERVER_UNAVAILABLE,
+ CLIENT_RESOURCE_EXHAUSTED,
+ FAILED_PRECONDITION_ERROR,
+ UNKNOWN_ERROR
+}
+
+public class MomentoGrpcErrorDetails {
+ public StatusCode code;
+ public string details;
+ public Metadata? metadata = null;
+
+ public MomentoGrpcErrorDetails(StatusCode code, string details, Metadata? metadata)
+ {
+ this.code = code;
+ this.details = details;
+ this.metadata = metadata;
+ }
+
+}
+
+public class MomentoErrorTransportDetails {
+ public MomentoGrpcErrorDetails grpc;
+
+ public MomentoErrorTransportDetails(MomentoGrpcErrorDetails grpc) {
+ this.grpc = grpc;
+ }
+}
+
public abstract class SdkException : Exception
{
- protected SdkException(string message) : base(message)
+ public MomentoErrorCode errorCode;
+ public MomentoErrorTransportDetails? transportDetails = null;
+
+ protected SdkException(string message, MomentoErrorCode errorCode) : base(message)
+ {
+ this.errorCode = errorCode;
+ }
+ protected SdkException(string message, MomentoErrorCode errorCode, MomentoErrorTransportDetails transportDetails) : base(message)
{
+ this.errorCode = errorCode;
+ this.transportDetails = transportDetails;
}
- protected SdkException(string message, Exception e) : base(message, e)
+ protected SdkException(string message, MomentoErrorCode errorCode, MomentoErrorTransportDetails? transportDetails, Exception e) : base(message, e)
{
+ this.errorCode = errorCode;
+ this.transportDetails = transportDetails;
}
}
diff --git a/src/Momento.Sdk/Exceptions/TimeoutException.cs b/src/Momento.Sdk/Exceptions/TimeoutException.cs
index 52aae6c2..91e79307 100644
--- a/src/Momento.Sdk/Exceptions/TimeoutException.cs
+++ b/src/Momento.Sdk/Exceptions/TimeoutException.cs
@@ -5,7 +5,10 @@
///
public class TimeoutException : SdkException
{
- public TimeoutException(string message) : base(message)
+ public TimeoutException(string message) : base(message, MomentoErrorCode.TIMEOUT_ERROR)
+ {
+ }
+ public TimeoutException(string message, MomentoErrorTransportDetails transportDetails) : base(message, MomentoErrorCode.TIMEOUT_ERROR, transportDetails)
{
}
}
diff --git a/src/Momento.Sdk/Exceptions/UnknownException.cs b/src/Momento.Sdk/Exceptions/UnknownException.cs
index a11a169b..ffe6e0e2 100644
--- a/src/Momento.Sdk/Exceptions/UnknownException.cs
+++ b/src/Momento.Sdk/Exceptions/UnknownException.cs
@@ -7,10 +7,10 @@ namespace Momento.Sdk.Exceptions;
///
public class UnknownException : SdkException
{
- public UnknownException(string message) : base(message)
+ public UnknownException(string message, MomentoErrorCode errorCode) : base(message, errorCode)
{
}
- public UnknownException(string message, Exception e) : base(message, e)
+ public UnknownException(string message, Exception e) : base(message, MomentoErrorCode.UNKNOWN_ERROR, null, e)
{
}
}