-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: data error response update #176
Changes from all commits
9d48b99
a8b5f5f
7c3aa6c
462abf7
efab849
0aa3060
bee2e90
5b620a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
using Momento.Sdk.Exceptions; | ||
|
||
public class CacheDeleteResponse | ||
{ | ||
public CacheDeleteResponse() | ||
public class Success : CacheDeleteResponse { } | ||
|
||
public class Error : CacheDeleteResponse | ||
{ | ||
private readonly SdkException _error; | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
public SdkException Exception | ||
{ | ||
get => _error; | ||
} | ||
|
||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,84 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Momento.Sdk.Exceptions; | ||
|
||
namespace Momento.Sdk.Responses; | ||
|
||
public class CacheGetBatchResponse | ||
public abstract class CacheGetBatchResponse | ||
{ | ||
public List<CacheGetResponse> Responses { get; } | ||
|
||
public CacheGetBatchResponse(IEnumerable<CacheGetResponse> responses) | ||
public class Success : CacheGetBatchResponse | ||
{ | ||
this.Responses = new(responses); | ||
} | ||
public List<CacheGetResponse> Responses { get; } | ||
|
||
public IEnumerable<CacheGetStatus> Status | ||
{ | ||
get => Responses.Select(response => response.Status); | ||
} | ||
public Success(IEnumerable<CacheGetResponse> responses) | ||
{ | ||
this.Responses = new(responses); | ||
} | ||
|
||
public IEnumerable<string?> Strings() | ||
{ | ||
return Responses.Select(response => response.String()); | ||
public IEnumerable<CacheGetStatus> Status | ||
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. @malandis you should look at this part. i'm not super familiar with this part of the API but some random thoughts I have are:
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.
|
||
{ | ||
get | ||
{ | ||
var ret = new List<CacheGetStatus>(); | ||
foreach (CacheGetResponse response in Responses) { | ||
if (response is CacheGetResponse.Hit hitResponse) { | ||
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. These look better/safer now, so thanks for changing them. I'm still feeling iffy about this part of the API as a whole, so I think we should revisit it and have a convo about it later this week, but I think it's okay for now for this PR. 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. Agreed, the batch stuff needs some love and we should take a closer look when time allows. |
||
ret.Add(hitResponse.Status); | ||
} else if (response is CacheGetResponse.Miss missResponse) { | ||
ret.Add(missResponse.Status); | ||
} | ||
} | ||
return ret; | ||
} | ||
} | ||
|
||
public IEnumerable<string?> Strings() | ||
{ | ||
var ret = new List<string?>(); | ||
foreach (CacheGetResponse response in Responses) | ||
{ | ||
if (response is CacheGetResponse.Hit hitResponse) { | ||
ret.Add(hitResponse.String()); | ||
} else if (response is CacheGetResponse.Miss missResponse) { | ||
ret.Add(null); | ||
} | ||
} | ||
return ret.ToArray(); | ||
} | ||
|
||
public IEnumerable<byte[]?> ByteArrays | ||
{ | ||
get | ||
{ | ||
var ret = new List<byte[]?>(); | ||
foreach (CacheGetResponse response in Responses) | ||
{ | ||
if (response is CacheGetResponse.Hit hitResponse) | ||
{ | ||
ret.Add(hitResponse.ByteArray); | ||
} else if (response is CacheGetResponse.Miss missResponse) { | ||
ret.Add(null); | ||
} | ||
} | ||
return ret.ToArray(); | ||
} | ||
} | ||
} | ||
|
||
public IEnumerable<byte[]?> ByteArrays | ||
public class Error : CacheGetBatchResponse | ||
{ | ||
get => Responses.Select(response => response.ByteArray); | ||
private readonly SdkException _error; | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
public SdkException Exception | ||
{ | ||
get => _error; | ||
} | ||
|
||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,52 @@ | ||
using Google.Protobuf; | ||
using Momento.Protos.CacheClient; | ||
|
||
using Momento.Sdk.Exceptions; | ||
namespace Momento.Sdk.Responses; | ||
|
||
public class CacheGetResponse : CacheGetResponseBase | ||
public abstract class CacheGetResponse | ||
{ | ||
public CacheGetResponse(_GetResponse response) : base(response.Result, response.CacheBody) | ||
public class Hit : CacheGetResponse | ||
{ | ||
public CacheGetStatus Status { get => CacheGetStatus.HIT; } | ||
protected readonly ByteString value; | ||
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. cool, thanks. I think we should merge this as-is because it's a good step forward, but would like to circle back quickly and see if the enum is still necessary at all. It feels like the only thing that is currently forcing us to keep it is that batch api, and if that's true, we should talk about options for getting rid of that bit, because having the enum here feels inconsistent since we got rid of it in the other places. 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. That sounds good. The enum shouldn't be necessary but removing it altogether as part of this effort seemed risky. |
||
|
||
public Hit(_GetResponse response) | ||
{ | ||
this.value = response.CacheBody; | ||
} | ||
|
||
public byte[] ByteArray | ||
{ | ||
get => value.ToByteArray(); | ||
} | ||
|
||
public string String() => value.ToStringUtf8(); | ||
} | ||
|
||
public class Miss : CacheGetResponse { | ||
public CacheGetStatus Status { | ||
get => CacheGetStatus.MISS; | ||
} | ||
|
||
public Miss() { } | ||
} | ||
|
||
public class Error : CacheGetResponse | ||
{ | ||
private readonly SdkException _error; | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
public SdkException Exception | ||
{ | ||
get => _error; | ||
} | ||
|
||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
public class CacheSetBatchResponse | ||
using Momento.Sdk.Exceptions; | ||
|
||
public abstract class CacheSetBatchResponse | ||
{ | ||
|
||
public class Success : CacheSetBatchResponse { } | ||
|
||
public class Error: CacheSetBatchResponse | ||
{ | ||
private readonly SdkException _error; | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
public SdkException Exception | ||
{ | ||
get => _error; | ||
} | ||
|
||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
public class CacheSetResponse | ||
using Momento.Sdk.Exceptions; | ||
|
||
public abstract class CacheSetResponse | ||
{ | ||
|
||
public class Success : CacheSetResponse { } | ||
|
||
public class Error : CacheSetResponse | ||
{ | ||
private readonly SdkException _error; | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
public SdkException Exception | ||
{ | ||
get => _error; | ||
} | ||
|
||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
} | ||
} |
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.
can't remember if we decided we were going to make these abstract, nbd though
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.
We did, and I did for the control responses but not the data ones. Fixed in efab849.