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.

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