apierr

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UserFriendlyError

func UserFriendlyError(err *APIError) string

UserFriendlyError converts API errors to user-friendly messages. Backend codes win over status codes — they encode the precise denial reason (policy block vs. provider rejection vs. token gate).

Types

type APIError

type APIError struct {
	StatusCode         int      `json:"-"`
	Code               string   `json:"code,omitempty"`
	ErrorCode          string   `json:"errorCode,omitempty"`
	ErrorMessage       string   `json:"errorMessage,omitempty"`
	LegacyError        string   `json:"error,omitempty"`
	Message            string   `json:"message,omitempty"`
	AccessInfo         string   `json:"accessInfo,omitempty"`
	Details            string   `json:"details,omitempty"`
	ConnectedProviders []string `json:"connectedProviders,omitempty"`
}

APIError represents an error response from the API. The backend uses two shapes:

  1. {code, message} — most endpoints
  2. {success:false, errorCode, errorMessage} — send/reply/forward

GET on a single email/thread may also return 404 with {accessInfo} to signal a policy denial (vs. genuinely missing).

func ParseAPIError

func ParseAPIError(resp *http.Response) *APIError

ParseAPIError extracts error details from an HTTP response. NOTE: This function does NOT close resp.Body - caller is responsible for closing. This allows the caller to use defer resp.Body.Close() consistently.

func (*APIError) EffectiveCode added in v0.3.0

func (e *APIError) EffectiveCode() string

EffectiveCode returns the backend error code from whichever shape the response used. Empty when neither field is populated.

func (*APIError) EffectiveMessage added in v0.3.0

func (e *APIError) EffectiveMessage() string

EffectiveMessage returns the user-facing description from whichever shape the response used. The 422 shape carries it in `message`; the send/reply/forward/modify/delete shape carries it in `errorMessage`; the legacy Drive 404 shape (`{ "error": "..." }`) carries it in `error`. All three are user-formatted and include my.porteden.com deep links / actionable guidance — prefer any of them over our own generic fallbacks.

func (*APIError) Error

func (e *APIError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL