feat: add OperationFailedError with actionable hints
The Kanboard API returns only true/false for many operations without explaining why they failed. Added OperationFailedError type that includes operation details and hints about possible causes. Updated MoveTaskPosition and MoveTaskToProject to use this new error type, providing users with actionable debugging information instead of generic "failed to move task" messages. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
508c3ac6d2
commit
449cd2626c
6 changed files with 131 additions and 5 deletions
26
errors.go
26
errors.go
|
|
@ -82,6 +82,26 @@ func (e *APIError) Error() string {
|
|||
return fmt.Sprintf("Kanboard API error (code %d): %s", e.Code, e.Message)
|
||||
}
|
||||
|
||||
// OperationFailedError represents an API operation that returned false without details.
|
||||
// The Kanboard API often returns only true/false without explaining why an operation failed.
|
||||
type OperationFailedError struct {
|
||||
Operation string
|
||||
Hints []string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *OperationFailedError) Error() string {
|
||||
msg := fmt.Sprintf("%s: operation failed", e.Operation)
|
||||
if len(e.Hints) > 0 {
|
||||
msg += " (possible causes: " + e.Hints[0]
|
||||
for _, hint := range e.Hints[1:] {
|
||||
msg += ", " + hint
|
||||
}
|
||||
msg += ")"
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// IsNotFound returns true if the error indicates a resource was not found.
|
||||
func IsNotFound(err error) bool {
|
||||
return errors.Is(err, ErrNotFound) ||
|
||||
|
|
@ -102,3 +122,9 @@ func IsAPIError(err error) bool {
|
|||
var apiErr *APIError
|
||||
return errors.As(err, &apiErr)
|
||||
}
|
||||
|
||||
// IsOperationFailed returns true if the error is an OperationFailedError.
|
||||
func IsOperationFailed(err error) bool {
|
||||
var opErr *OperationFailedError
|
||||
return errors.As(err, &opErr)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue