@@ -2,6 +2,7 @@ package lending
22
33import (
44 "encoding/hex"
5+ "errors"
56 "fmt"
67
78 sdkmath "cosmossdk.io/math"
@@ -24,7 +25,9 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) error {
2425// EndBlocker called at the end of each block
2526func EndBlocker (ctx sdk.Context , k keeper.Keeper ) error {
2627 // handle pending loans
27- handlePendingLoans (ctx , k )
28+ if err := handlePendingLoans (ctx , k ); err != nil {
29+ return err
30+ }
2831
2932 // handle active loans
3033 handleActiveLoans (ctx , k )
@@ -37,7 +40,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) error {
3740}
3841
3942// handleActiveLoans handles pending loans
40- func handlePendingLoans (ctx sdk.Context , k keeper.Keeper ) {
43+ func handlePendingLoans (ctx sdk.Context , k keeper.Keeper ) error {
4144 // handler on loan rejected
4245 rejectHandler := func (loan * types.Loan , authorizationId uint64 , reason error ) {
4346 if authorizationId > 0 {
@@ -99,6 +102,10 @@ func handlePendingLoans(ctx sdk.Context, k keeper.Keeper) {
99102
100103 // approve loan
101104 if err := k .HandleApproval (ctx , loan ); err != nil {
105+ if errors .Is (err , types .ErrUnexpected ) {
106+ return err
107+ }
108+
102109 rejectHandler (loan , authorizationId , err )
103110 continue
104111 }
@@ -110,6 +117,8 @@ func handlePendingLoans(ctx sdk.Context, k keeper.Keeper) {
110117 }
111118 }
112119 }
120+
121+ return nil
113122}
114123
115124// handleActiveLoans handles active loans
0 commit comments