Loggest thy stuff
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.

35 lines
774 B

  1. package slerrors
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. )
  6. type ErrorResponse struct {
  7. Code int `json:"errorCode"`
  8. Message string `json:"errorMessage"`
  9. }
  10. func Respond(c *gin.Context, err error) {
  11. if IsNotFound(err) {
  12. c.JSON(http.StatusNotFound, ErrorResponse{
  13. Code: http.StatusNotFound,
  14. Message: err.Error(),
  15. })
  16. } else if IsForbidden(err) {
  17. c.JSON(http.StatusForbidden, ErrorResponse{
  18. Code: http.StatusForbidden,
  19. Message: err.Error(),
  20. })
  21. } else if IsBadRequest(err) {
  22. c.JSON(http.StatusBadRequest, ErrorResponse{
  23. Code: http.StatusBadRequest,
  24. Message: err.Error(),
  25. })
  26. } else {
  27. c.JSON(http.StatusInternalServerError, ErrorResponse{
  28. Code: http.StatusInternalServerError,
  29. Message: err.Error(),
  30. })
  31. }
  32. }