Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorCode(err error) string
- func ErrorData(err error) string
- func ErrorDebugInfo(err error) string
- func ErrorMessage(err error) string
- func ErrorStatusCode(code string) int
- func WriteError(c echo.Context, err error) error
- func WriteSuccess(c echo.Context, payload any) error
- type Config
- type Error
- type HTTPError
- type HTTPSuccess
- type PostgrestConfig
Constants ¶
const ( ECONFLICT = "conflict" EFORBIDDEN = "forbidden" EINTERNAL = "internal" EINVALID = "invalid" ENOTFOUND = "not_found" ENOTIMPLEMENTED = "not_implemented" EUNAUTHORIZED = "unauthorized" )
Application error codes.
These are meant to be generic and they map well to HTTP error codes.
Variables ¶
var DefaultConfig = Config{ Postgrest: PostgrestConfig{ Version: "v10.0.0", DBAnonRole: "postgrest_api", Port: 3000, MaxRows: 2000, }, }
Functions ¶
func ErrorCode ¶
ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.
func ErrorData ¶ added in v1.0.428
ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".
func ErrorDebugInfo ¶
ErrorDebugInfo unwraps an application error and returns its debug message.
func ErrorMessage ¶
ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".
func ErrorStatusCode ¶
ErrorStatusCode returns the associated HTTP status code for an application error code.
func WriteError ¶
func WriteSuccess ¶ added in v1.0.510
Types ¶
type Error ¶
type Error struct { // Machine-readable error code. Code string // Human-readable error message. Message string // Machine-machine error message. Data string // DebugInfo contains low-level internal error details that should only be logged. // End-users should never see this. DebugInfo string }
Error represents an application-specific error.
func Errorf ¶
Errorf is a helper function to return an Error with a given code and formatted message.
type HTTPError ¶
type HTTPError struct { Err string `json:"error"` Message string `json:"message,omitempty"` // Data for machine-machine communication. // usually contains a JSON data. Data string `json:"data,omitempty"` }
func HTTPErrorFromErr ¶ added in v1.0.494
type HTTPSuccess ¶
type PostgrestConfig ¶ added in v1.0.564
type PostgrestConfig struct { Port int Disable bool LogLevel string URL string Version string JWTSecret string DBAnonRole string // A hard limit to the number of rows PostgREST will fetch from a view, table, or stored procedure. // Limits payload size for accidental or malicious requests. MaxRows int }