Skip to content

Commit 3c20cd0

Browse files
nawikartastaphobia
andauthored
Bug: Error RESOURCE_EXHAUSTED GetTransactions (#849)
* Pagination can't be empty * set default pagination Co-authored-by: Nawi Kartini <[email protected]> Co-authored-by: Ariasa Ketut <[email protected]>
1 parent 4b3aa26 commit 3c20cd0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

api/handler/transactionHandler.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55

66
"github.com/zoobc/zoobc-core/api/service"
77
"github.com/zoobc/zoobc-core/common/chaintype"
8+
"github.com/zoobc/zoobc-core/common/constant"
89
"github.com/zoobc/zoobc-core/common/model"
10+
"google.golang.org/grpc/codes"
11+
"google.golang.org/grpc/status"
912
)
1013

1114
// TransactionHandler handles requests related to transactions
@@ -41,6 +44,19 @@ func (th *TransactionHandler) GetTransactions(
4144
err error
4245
)
4346

47+
pagination := req.GetPagination()
48+
if pagination == nil {
49+
pagination = &model.Pagination{
50+
OrderField: "timestamp",
51+
OrderBy: model.OrderBy_DESC,
52+
Page: 0,
53+
Limit: constant.MaxAPILimitPerPage,
54+
}
55+
}
56+
if pagination.GetLimit() > constant.MaxAPILimitPerPage {
57+
return nil, status.Errorf(codes.OutOfRange, "Limit exceeded, max. %d", constant.MaxAPILimitPerPage)
58+
}
59+
4460
chainType := chaintype.GetChainType(0)
4561
response, err = th.Service.GetTransactions(chainType, req)
4662
if err != nil {

0 commit comments

Comments
 (0)