-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
30 lines (25 loc) · 720 Bytes
/
error.go
File metadata and controls
30 lines (25 loc) · 720 Bytes
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
28
29
30
// Copyright 2018 hryyan. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package b2
import (
"errors"
"fmt"
"net/http"
)
type ErrorResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Status int64 `json:"status"`
}
func handleErrorResponse(response *http.Response) error {
var errorResponse ErrorResponse
if err := unmarshalResponseBody(response, &errorResponse); err != nil {
return err
}
return errors.New(errorResponse.Message)
}
func handleUnknownResponse(response *http.Response) error {
var errStr = fmt.Sprintf("Unknown http status %d\n", response.StatusCode)
return errors.New(errStr)
}