mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #40028 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed telemetry misclassification where client-side errors were incorrectly reported as server errors. Client-side errors and request cancellations are now properly categorized for improved error tracking and observability. * **Tests** * Added test coverage for client error detection and context cancellation handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
103 lines
2.2 KiB
Go
103 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
type alreadyExistsError struct {
|
|
fleet.ErrorWithUUID
|
|
}
|
|
|
|
func (a *alreadyExistsError) Error() string {
|
|
return "Entity already exists"
|
|
}
|
|
|
|
func (a *alreadyExistsError) IsExists() bool {
|
|
return true
|
|
}
|
|
|
|
func (a *alreadyExistsError) IsClientError() bool {
|
|
return true
|
|
}
|
|
|
|
func newAlreadyExistsError() *alreadyExistsError {
|
|
return &alreadyExistsError{}
|
|
}
|
|
|
|
type notFoundError struct {
|
|
fleet.ErrorWithUUID
|
|
}
|
|
|
|
func (e *notFoundError) Error() string {
|
|
return "not found"
|
|
}
|
|
|
|
func (e *notFoundError) IsNotFound() bool {
|
|
return true
|
|
}
|
|
|
|
func (e *notFoundError) IsClientError() bool {
|
|
return true
|
|
}
|
|
|
|
func newNotFoundError() *notFoundError {
|
|
return ¬FoundError{}
|
|
}
|
|
|
|
// ssoErrCode defines a code for the type of SSO error that occurred. This is
|
|
// used to indicate to the frontend why the SSO login attempt failed so that
|
|
// it can provide a helpful and appropriate error message.
|
|
type ssoErrCode string
|
|
|
|
// List of valid SSO error codes.
|
|
const (
|
|
ssoOtherError ssoErrCode = "error"
|
|
ssoOrgDisabled ssoErrCode = "org_disabled"
|
|
ssoAccountDisabled ssoErrCode = "account_disabled"
|
|
ssoAccountInvalid ssoErrCode = "account_invalid"
|
|
)
|
|
|
|
// ssoError is an error that occurs during the single sign-on flow. Its code
|
|
// indicates the type of error.
|
|
type ssoError struct {
|
|
err error
|
|
code ssoErrCode
|
|
|
|
fleet.ErrorWithUUID
|
|
}
|
|
|
|
func newSSOError(err error, code ssoErrCode) *ssoError {
|
|
return &ssoError{
|
|
err: err,
|
|
code: code,
|
|
}
|
|
}
|
|
|
|
func (e *ssoError) Error() string {
|
|
return string(e.code) + ": " + e.err.Error()
|
|
}
|
|
|
|
func (e *ssoError) Unwrap() error {
|
|
return e.err
|
|
}
|
|
|
|
// gitOpsValidationError is an error that occurs during validating fields in the yaml spec.
|
|
type gitOpsValidationError struct {
|
|
message string
|
|
}
|
|
|
|
func (e *gitOpsValidationError) Error() string {
|
|
return e.message
|
|
}
|
|
|
|
func (e *gitOpsValidationError) WithFileContext(baseDir, filename string) error {
|
|
fileFullPath := filepath.Join(baseDir, filename)
|
|
return fmt.Errorf("Couldn't edit %q at: %q. %s", filename, fileFullPath, e.message)
|
|
}
|
|
|
|
func newGitOpsValidationError(message string) *gitOpsValidationError {
|
|
return &gitOpsValidationError{message: message}
|
|
}
|