diff --git a/CHANGELOG.md b/CHANGELOG.md index 72bb18f..7e1a415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ How to release a new version: ## [Unreleased] +## [0.5.0] - 2022-01-20 +### Added +- `ErrorResponseOptions` contains public error message. +- `ErrorResponseOptions` contains request ID. +- Error response options: + - `WithErrorMessage` + - `WithRequestID` + ## [0.4.0] - 2022-01-12 ### Changed - JSON tags in `ErrorResponseOptions`. @@ -32,7 +40,8 @@ How to release a new version: ### Added - Added Changelog. -[Unreleased]: https://github.com/strvcom/strv-backend-go-net/compare/v0.4.0...HEAD +[Unreleased]: https://github.com/strvcom/strv-backend-go-net/compare/v0.5.0...HEAD +[0.5.0]: https://github.com/strvcom/strv-backend-go-net/compare/v0.4.0...v0.5.0 [0.4.0]: https://github.com/strvcom/strv-backend-go-net/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/strvcom/strv-backend-go-net/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/strvcom/strv-backend-go-net/compare/v0.1.0...v0.2.0 diff --git a/http/response.go b/http/response.go index 1be4ba5..c2f0ced 100644 --- a/http/response.go +++ b/http/response.go @@ -89,13 +89,22 @@ func WriteErrorResponse( type ErrorResponseOptions struct { ResponseOptions `json:"-"` - Err error `json:"-"` - ErrCode string `json:"errorCode"` - ErrData any `json:"errorData,omitempty"` + RequestID string `json:"requestId,omitempty"` + + Err error `json:"-"` + ErrCode string `json:"errorCode"` + ErrMessage string `json:"errorMessage,omitempty"` + ErrData any `json:"errorData,omitempty"` } type ErrorResponseOption func(*ErrorResponseOptions) +func WithRequestID(id string) ErrorResponseOption { + return func(o *ErrorResponseOptions) { + o.RequestID = id + } +} + func WithError(err error) ErrorResponseOption { return func(o *ErrorResponseOptions) { o.Err = err @@ -108,6 +117,12 @@ func WithErrorCode(code string) ErrorResponseOption { } } +func WithErrorMessage(msg string) ErrorResponseOption { + return func(o *ErrorResponseOptions) { + o.ErrMessage = msg + } +} + func WithErrorData(data any) ErrorResponseOption { return func(o *ErrorResponseOptions) { o.ErrData = data