From 59b2969d773c6e53c7ed2ad5c20305bf2bef6970 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 16 Jan 2024 21:53:03 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20Add=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 3 +++ interface.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 go.mod create mode 100644 interface.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..52f9d44 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module codeberg.org/danjones000/responsable-errors + +go 1.21.5 diff --git a/interface.go b/interface.go new file mode 100644 index 0000000..1169966 --- /dev/null +++ b/interface.go @@ -0,0 +1,29 @@ +package errors + +// ResponsableError is an error that has information useful in an HTTP response. +// The string returned by Error should be suitable for logging useful information +// to assist debugging the error. +// Status should return an appropriate HTTP status. +// Msg should return a message suitable to display to the end user. If the message +// returned by Error is safe for the end user, it may simply call that. +type ResponsableError interface { + Error() string + Status() int + Msg() string +} + +// UnwrappableError allows a ResponsableError to wrap another error. +// It may be appropriate for Error() to delegate to the wrapped error. +type UnwrappableError interface { + ResponsableError + Unwrap() error +} + +// UnwrappableErrorrs allows a ResponsableError to wrap multiple errors. +// It may be appropriate for Error() to either delegate to the first error, +// the last error, or to concatenate the return values of all wrapped errors, +// similar to errors returned by errors.Join +type UnwrappableErrors interface { + ResponsableError + Unwrap() []error +}