-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
29 lines (25 loc) · 765 Bytes
/
errors.go
File metadata and controls
29 lines (25 loc) · 765 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
package sourcify
import (
"fmt"
"github.com/goccy/go-json"
"github.com/google/uuid"
"io"
)
var (
// ErrInvalidParamType represents an error when a parameter of an invalid type is encountered.
ErrInvalidParamType = func(t string) error {
return fmt.Errorf("encountered a parameter of invalid type: %s", t)
}
)
type ErrorResponse struct {
ErrorId uuid.UUID `json:"errorId"`
CustomCode string `json:"customCode"`
Message string `json:"message"`
}
func ToErrorResponse(response io.ReadCloser) error {
var errorResp ErrorResponse
if err := json.NewDecoder(response).Decode(&errorResp); err == nil && errorResp.Message != "" {
return fmt.Errorf("sourcify returned error (%s): %s", errorResp.CustomCode, errorResp.Message)
}
return nil
}