File: errors.go

package info (click to toggle)
geoipupdate 7.1.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 432 kB
  • sloc: sh: 103; makefile: 70; perl: 51
file content (27 lines) | stat: -rw-r--r-- 584 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Package internal provides internal structures.
package internal

import (
	"errors"
	"fmt"
)

// HTTPError is an error from performing an HTTP request.
type HTTPError struct {
	Body       string
	StatusCode int
}

func (h HTTPError) Error() string {
	return fmt.Sprintf("received HTTP status code: %d: %s", h.StatusCode, h.Body)
}

// IsPermanentError returns true if the error is non-retriable.
func IsPermanentError(err error) bool {
	var httpErr HTTPError
	if errors.As(err, &httpErr) && httpErr.StatusCode >= 400 && httpErr.StatusCode < 500 {
		return true
	}

	return false
}