-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhanced TxApplied subscription to show success/failure details
- Loading branch information
Showing
18 changed files
with
351 additions
and
73 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Runtime.Serialization; | ||
using Bencodex.Types; | ||
using Libplanet.Action; | ||
|
||
[Serializable] | ||
public class ActionException : Exception, IExtractableException, ISerializable | ||
{ | ||
// 새로운 예외 클래스에서 사용할 메타데이터 프로퍼티 | ||
private readonly string ErrorType; | ||
private readonly string ErrorMessage; | ||
private readonly int? ErrorCode; | ||
public IValue Metadata { get; } | ||
|
||
public ActionException(string message, string errorType, int? errorCode) | ||
: base(message) | ||
{ | ||
ErrorType = errorType; | ||
ErrorMessage = message; | ||
ErrorCode = errorCode; | ||
|
||
var metaData = new Dictionary( | ||
new[] | ||
{ | ||
new KeyValuePair<IKey, IValue>( | ||
(Text) "errorType", | ||
(Text) errorType | ||
), | ||
new KeyValuePair<IKey, IValue>( | ||
(Text) "errorMessage", | ||
(Text) message | ||
) | ||
} | ||
); | ||
|
||
if (errorCode is int code) | ||
{ | ||
Metadata = metaData.SetItem( | ||
(Text)"errorCode", | ||
(Integer)code | ||
); | ||
} | ||
|
||
Metadata = metaData; | ||
|
||
} | ||
protected ActionException(SerializationInfo info, StreamingContext context) | ||
Check warning on line 46 in backend/app/Savor22b/Action/Exceptions/ActionException.cs GitHub Actions / build-and-tests
Check warning on line 46 in backend/app/Savor22b/Action/Exceptions/ActionException.cs GitHub Actions / build-and-tests
|
||
: base(info, context) | ||
{ | ||
if (info.GetString(nameof(ErrorType)) is { } errorType) | ||
{ | ||
ErrorType = errorType; | ||
} | ||
|
||
if (info.GetString(nameof(ErrorMessage)) is { } errorMessage) | ||
{ | ||
ErrorMessage = errorMessage; | ||
} | ||
|
||
if (info.GetInt32(nameof(ErrorCode)) is int errorCode) | ||
{ | ||
ErrorCode = errorCode; | ||
} | ||
|
||
if (info.GetValue(nameof(Metadata), typeof(IValue)) is IValue metadata) | ||
{ | ||
Metadata = metadata; | ||
} | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
|
||
info.AddValue(nameof(ErrorType), ErrorType); | ||
info.AddValue(nameof(ErrorMessage), ErrorMessage); | ||
info.AddValue(nameof(ErrorCode), ErrorCode); | ||
|
||
if (Metadata is { } metadata) | ||
{ | ||
info.AddValue(nameof(Metadata), metadata); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/app/Savor22b/Action/Exceptions/HouseAlreadyPlacedException.cs
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,11 @@ | ||
namespace Savor22b.Action.Exceptions; | ||
|
||
|
||
[Serializable] | ||
public class HouseAlreadyPlacedException : ActionException | ||
{ | ||
public HouseAlreadyPlacedException(string message, int? errorCode = null) | ||
: base(message, "HouseAlreadyPlaced", errorCode) | ||
{ | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../Action/InvalidTransferSignerException.cs → ...eptions/InvalidTransferSignerException.cs
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
11 changes: 11 additions & 0 deletions
11
backend/app/Savor22b/Action/Exceptions/InvalidVillageException.cs
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,11 @@ | ||
namespace Savor22b.Action.Exceptions; | ||
|
||
|
||
[Serializable] | ||
public class InvalidVillageException : ActionException | ||
{ | ||
public InvalidVillageException(string message, int? errorCode = null) | ||
: base(message, "InvalidVillage", errorCode) | ||
{ | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
backend/app/Savor22b/Action/Exceptions/NotEnoughRawMaterialsException.cs
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,13 @@ | ||
namespace Savor22b.Action.Exceptions; | ||
|
||
using System.Runtime.Serialization; | ||
|
||
|
||
[Serializable] | ||
public class NotEnoughRawMaterialsException : ActionException | ||
{ | ||
public NotEnoughRawMaterialsException(string message, int? errorCode = null) | ||
: base(message, "NotEnoughRawMaterials", errorCode) | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/app/Savor22b/Action/Exceptions/NotFoundTableDataException.cs
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,11 @@ | ||
namespace Savor22b.Action.Exceptions; | ||
|
||
|
||
[Serializable] | ||
public class NotFoundTableDataException : ActionException | ||
{ | ||
public NotFoundTableDataException(string message, int? errorCode = null) | ||
: base(message, "NotFoundTableData", errorCode) | ||
{ | ||
} | ||
} |
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
22 changes: 0 additions & 22 deletions
22
backend/app/Savor22b/Action/NotEnoughRawMaterialsException.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Savor22b.GraphTypes; | ||
|
||
using Bencodex.Types; | ||
using Libplanet.Headless.Extensions; | ||
|
||
public class ExceptionMetadata | ||
{ | ||
public string errorType { get; set; } | ||
public string errorMessage { get; set; } | ||
public int? errorCode { get; set; } | ||
|
||
public ExceptionMetadata(string errorType, string errorMessage, int? errorCode) | ||
{ | ||
this.errorType = errorType; | ||
this.errorMessage = errorMessage; | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ExceptionMetadata(Bencodex.Types.IValue encoded) | ||
{ | ||
if (encoded is Bencodex.Types.Dictionary dict) | ||
{ | ||
// Bencodex 데이터에서 필요한 값을 꺼내서 ExceptionMetadata 객체에 매핑합니다. | ||
if (dict.TryGetValue((Text)"errorType", out var errorTypeValue) && errorTypeValue is Text errorTypeText) | ||
{ | ||
errorType = errorTypeText.Value; | ||
} | ||
|
||
if (dict.TryGetValue((Text)"errorMessage", out var errorMessageValue) && errorMessageValue is Text errorMessageText) | ||
{ | ||
errorMessage = errorMessageText.Value; | ||
} | ||
|
||
if (dict.TryGetValue((Text)"errorCode", out var errorCodeValue) && errorCodeValue is Integer errorCodeInteger) | ||
{ | ||
errorCode = (int)errorCodeInteger; | ||
} | ||
} | ||
} | ||
} |
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,28 @@ | ||
using Bencodex.Types; | ||
using GraphQL.Types; | ||
using Savor22b.GraphTypes; | ||
|
||
|
||
public class ExceptionMetadataType : ObjectGraphType<ExceptionMetadata> | ||
{ | ||
public ExceptionMetadataType() | ||
{ | ||
Field<NonNullGraphType<StringGraphType>>( | ||
name: "errorType", | ||
description: "The error type of the exception.", | ||
resolve: context => context.Source.errorType | ||
); | ||
|
||
Field<NonNullGraphType<StringGraphType>>( | ||
name: "errorMessage", | ||
description: "The error message of the exception.", | ||
resolve: context => context.Source.errorMessage | ||
); | ||
|
||
Field<IntGraphType>( | ||
name: "errorCode", | ||
description: "The error code of the exception.", | ||
resolve: context => context.Source.errorCode | ||
); | ||
} | ||
} |
Oops, something went wrong.