-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package serviceLogs | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ErrInvalidRequest represents errors related to invalid API requests | ||
type ErrInvalidRequest struct { | ||
Check failure on line 9 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux amd64
Check failure on line 9 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux 386
Check failure on line 9 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin amd64
Check failure on line 9 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin arm64
|
||
Op string | ||
Message string | ||
Err error | ||
} | ||
|
||
func (e *ErrInvalidRequest) Error() string { | ||
if e.Err != nil { | ||
return fmt.Sprintf("%s: %s: %v", e.Op, e.Message, e.Err) | ||
} | ||
return fmt.Sprintf("%s: %s", e.Op, e.Message) | ||
} | ||
|
||
func (e *ErrInvalidRequest) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
// ErrLogResponse represents errors related to log response parsing or validation | ||
type ErrLogResponse struct { | ||
Check failure on line 27 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux amd64
Check failure on line 27 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux 386
Check failure on line 27 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin amd64
Check failure on line 27 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin arm64
|
||
StatusCode int | ||
Message string | ||
Err error | ||
} | ||
|
||
func (e *ErrLogResponse) Error() string { | ||
if e.Err != nil { | ||
return fmt.Sprintf("log response error (status %d): %s: %v", e.StatusCode, e.Message, e.Err) | ||
} | ||
return fmt.Sprintf("log response error (status %d): %s", e.StatusCode, e.Message) | ||
} | ||
|
||
func (e *ErrLogResponse) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
// NewInvalidRequestError creates a new ErrInvalidRequest | ||
func NewInvalidRequestError(op string, message string, err error) error { | ||
Check failure on line 45 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux amd64
Check failure on line 45 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux 386
Check failure on line 45 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin amd64
Check failure on line 45 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin arm64
|
||
return &ErrInvalidRequest{ | ||
Op: op, | ||
Message: message, | ||
Err: err, | ||
} | ||
} | ||
|
||
// NewLogResponseError creates a new ErrLogResponse | ||
func NewLogResponseError(statusCode int, message string, err error) error { | ||
Check failure on line 54 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux amd64
Check failure on line 54 in src/serviceLogs/errors.go GitHub Actions / Build && tests for linux 386
Check failure on line 54 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin amd64
Check failure on line 54 in src/serviceLogs/errors.go GitHub Actions / Build && tests for darwin arm64
|
||
return &ErrLogResponse{ | ||
StatusCode: statusCode, | ||
Message: message, | ||
Err: err, | ||
} | ||
} | ||
|
||
// IsInvalidRequestError checks if the error is an ErrInvalidRequest | ||
func IsInvalidRequestError(err error) bool { | ||
var target *ErrInvalidRequest | ||
return errors.As(err, &target) | ||
} | ||
|
||
// IsLogResponseError checks if the error is an ErrLogResponse | ||
func IsLogResponseError(err error) bool { | ||
var target *ErrLogResponse | ||
return errors.As(err, &target) | ||
} |