Skip to content

Commit

Permalink
feat: 忽略阿里云限流以及服务器内部错误
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Jun 27, 2019
1 parent 7aba7ac commit ca55510
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aliacm

// Error ACM错误
type Error string

func (e Error) Error() string {
return string(e)
}

const (
serviceUnavailableErr = Error("ServiceUnavailable")
internalServerErr = Error("InternalServerError")
)

// ShouldIgnore 忽略一些不想关心的错误
func ShouldIgnore(err error) bool {
if err == serviceUnavailableErr || err == internalServerErr {
return true
}
return false
}
9 changes: 9 additions & 0 deletions long_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ func (d *Diamond) LongPull(unit Unit, contentMD5 string) (string, error) {
if err != nil {
return "", err
}

switch response.StatusCode() {
case http.StatusServiceUnavailable:
return "", serviceUnavailableErr
case http.StatusInternalServerError:
return "", internalServerErr
}

if !response.Success() {
return "", errors.New(response.String())
}

ret := url.QueryEscape(strings.Join([]string{unit.DataID, unit.Group, d.option.tenant}, wordSeparator) + lineSeparator)
if contentMD5 == "" ||
ret == strings.TrimSpace(response.String()) {
Expand Down

0 comments on commit ca55510

Please sign in to comment.