hermez-node/api/handlers.go
api/handlers.goRaw
1package api
2
3import (
4 "database/sql"
5 "errors"
6 "net/http"
7
8 "github.com/gin-gonic/gin"
9 "github.com/hermeznetwork/hermez-node/db/historydb"
10)
11
12const (
13 // maxLimit is the max permited items to be returned in paginated responses
14 maxLimit uint = 2049
15
16 // dfltOrder indicates how paginated endpoints are ordered if not specified
17 dfltOrder = historydb.OrderAsc
18
19 // dfltLimit indicates the limit of returned items in paginated responses if the query param limit is not provided
20 dfltLimit uint = 20
21
22 // 2^32 -1
23 maxUint32 = 4294967295
24
25 // 2^64 /2 -1
26 maxInt64 = 9223372036854775807
27)
28
29var (
30 // ErrNillBidderAddr is used when a nil bidderAddr is received in the getCoordinator method
31 ErrNillBidderAddr = errors.New("biderAddr can not be nil")
32)
33
34func retSQLErr(err error, c *gin.Context) {
35 if err == sql.ErrNoRows {
36 c.JSON(http.StatusNotFound, errorMsg{
37 Message: err.Error(),
38 })
39 } else {
40 c.JSON(http.StatusInternalServerError, errorMsg{
41 Message: err.Error(),
42 })
43 }
44}
45
46func retBadReq(err error, c *gin.Context) {
47 c.JSON(http.StatusBadRequest, errorMsg{
48 Message: err.Error(),
49 })
50}