Add comprehensive documentation comments

This commit is contained in:
Oliver Jakoubek 2025-11-18 18:36:48 +01:00
commit 9db82f92c5
6 changed files with 128 additions and 26 deletions

View file

@ -5,7 +5,9 @@ import (
"fmt"
)
// APIError repräsentiert einen API-Fehler
// APIError represents an error response from the Sendamatic API.
// It includes the HTTP status code, error message, and optional additional context
// such as validation errors, JSON path information, and SMTP codes.
type APIError struct {
StatusCode int `json:"-"`
Message string `json:"error"`
@ -15,6 +17,8 @@ type APIError struct {
SMTPCode int `json:"smtp_code,omitempty"`
}
// Error implements the error interface and returns a formatted error message.
// If validation errors are present, they are included with the JSON path context.
func (e *APIError) Error() string {
if e.ValidationErrors != "" {
return fmt.Sprintf("sendamatic api error (status %d): %s (path: %s)",
@ -23,6 +27,8 @@ func (e *APIError) Error() string {
return fmt.Sprintf("sendamatic api error (status %d): %s", e.StatusCode, e.Message)
}
// parseErrorResponse attempts to parse an API error response body into an APIError.
// If the body cannot be parsed as JSON, it uses the raw body as the error message.
func parseErrorResponse(statusCode int, body []byte) error {
var apiErr APIError
apiErr.StatusCode = statusCode