api_error.go 461 B

123456789101112131415161718192021222324252627
  1. package api
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type ApiError struct {
  7. Message string
  8. StatusCode int
  9. }
  10. func (e *ApiError) Error() string {
  11. return fmt.Sprintf("status %d with err: %s", e.StatusCode, e.Message)
  12. }
  13. func IsApiError(err error) bool {
  14. _, ok := err.(*ApiError)
  15. return ok
  16. }
  17. func IsFileNotInAlbumError(err error) bool {
  18. if apiErr, ok := err.(*ApiError); ok {
  19. return strings.Contains(apiErr.Message, "FILE_NOT_FOUND_IN_ALBUM")
  20. }
  21. return false
  22. }