Merge PR #5421: Refactor Error Handling
This commit is contained in:
@@ -25,19 +25,24 @@ Let us break it down:
|
||||
|
||||
## Implementation of a module `handler`s
|
||||
|
||||
Module `handler`s are typically implemented in a `./handler.go` file inside the module's folder. The [module manager](./module-manager.md) is used to add the module's `handler`s to the [application's `router`](../core/baseapp.md#message-routing) via the `NewHandler()` method. Typically, the manager's `NewHandler()` method simply calls a `NewHandler()` method defined in `handler.go`, which looks like the following:
|
||||
Module `handler`s are typically implemented in a `./handler.go` file inside the module's folder. The
|
||||
[module manager](./module-manager.md) is used to add the module's `handler`s to the
|
||||
[application's `router`](../core/baseapp.md#message-routing) via the `NewHandler()` method. Typically,
|
||||
the manager's `NewHandler()` method simply calls a `NewHandler()` method defined in `handler.go`,
|
||||
which looks like the following:
|
||||
|
||||
```go
|
||||
func NewHandler(keeper Keeper) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
||||
switch msg := msg.(type) {
|
||||
case MsgType1:
|
||||
return handleMsgType1(ctx, keeper, msg)
|
||||
|
||||
case MsgType2:
|
||||
return handleMsgType2(ctx, keeper, msg)
|
||||
|
||||
default:
|
||||
errMsg := fmt.Sprintf("Unrecognized nameservice Msg type: %v", msg.Type())
|
||||
return sdk.ErrUnknownRequest(errMsg).Result()
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user