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