allow to set any message as error

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-25 14:16:55 +03:00
parent cf9d05d4f7
commit 0a59653c70
3 changed files with 25 additions and 129 deletions

View File

@@ -2,6 +2,7 @@ package http
import (
"context"
"fmt"
"net/http"
"github.com/unistack-org/micro/v3/server"
@@ -12,6 +13,18 @@ type rspCodeVal struct {
code int
}
func SetError(err interface{}) error {
return &Error{err: err}
}
type Error struct {
err interface{}
}
func (err *Error) Error() string {
return fmt.Sprintf("%v", err.err)
}
// SetRspCode saves response code in context, must be used by handler to specify http code
func SetRspCode(ctx context.Context, code int) {
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {