Overview
The Garnet API uses typed errors from thetypes/errs package to provide clear, actionable error information. All errors implement the standard Go error interface and support errors.Is for type checking.
Error Types
InvalidArgumentError
Returned when request parameters are invalid or malformed.- Missing required fields
- Invalid enum values
- Malformed data (e.g., invalid IP address, bad CIDR notation)
- Empty fields where non-empty is required
- Fields exceeding maximum length
NotFoundError
Returned when a requested resource does not exist.- Resource ID doesn’t exist
- Resource was deleted
- User doesn’t have access to the resource
UnauthorizedError
Returned when authentication fails or token is invalid.- Missing authentication token
- Invalid or expired token
- Token doesn’t have required permissions
PermissionDeniedError
Returned when user is authenticated but lacks necessary permissions.- User role doesn’t allow the operation
- Resource belongs to different project
- Attempting to modify system-level resources
ConflictError
Returned when operation conflicts with existing state.- Attempting to create duplicate resource
- Resource already in desired state
- Concurrent modification conflict
InternalServerError
Returned when an unexpected server error occurs.- Database connection issues
- Unexpected server state
- Third-party service failures
Error Checking
Using errors.Is
Check error types using Go’s standarderrors.Is:
Checking Specific Errors
Check for specific error constants:Is Helper Function
Check if error is any Garnet API error:Domain-Specific Errors
Agent Errors
Event Errors
Issue Errors
Network Policy Errors
Webhook Errors
Project Setting Errors
Context Errors
Error Handling Best Practices
1. Always Check Errors
2. Use Type Checks for Different Handling
3. Provide Context
4. Check Specific Errors When Needed
HTTP Status Code Mapping
| Error Type | HTTP Status | Code |
|---|---|---|
| InvalidArgumentError | 400 | Bad Request |
| UnauthorizedError | 401 | Unauthorized |
| PermissionDeniedError | 403 | Forbidden |
| NotFoundError | 404 | Not Found |
| ConflictError | 409 | Conflict |
| InternalServerError | 500 | Internal Server Error |
