You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

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