dcsunny 4 年之前
父节点
当前提交
15720d4dc4
共有 2 个文件被更改,包括 0 次插入56 次删除
  1. 0 3
      http/handle.go
  2. 0 53
      http/middleware/status/status.go

+ 0 - 3
http/handle.go

@@ -3,7 +3,6 @@ package http
 import (
 	"bytes"
 	json2 "encoding/json"
-	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
@@ -102,7 +101,6 @@ func ErrHandle(w http.ResponseWriter, r *http.Request, err error) {
 	if code == 1000 {
 		return
 	}
-	fmt.Println(fmt.Sprintf("code:%d", code))
 	w.Header().Set(ContentTypeHeader, "application/json; charset=utf-8")
 	if code == 0 {
 		w.WriteHeader(200)
@@ -126,7 +124,6 @@ func ErrHandle(w http.ResponseWriter, r *http.Request, err error) {
 		w.WriteHeader(http.StatusInternalServerError)
 		return
 	}
-	fmt.Println(string(data))
 	w.Write(data)
 
 	//se := errors.FromError(err)

+ 0 - 53
http/middleware/status/status.go

@@ -1,53 +0,0 @@
-package status
-
-import (
-	"context"
-
-	"github.com/go-kratos/kratos/v2/errors"
-	"github.com/go-kratos/kratos/v2/middleware"
-	//lint:ignore SA1019 grpc
-)
-
-// HandlerFunc is middleware error handler.
-type HandlerFunc func(error) error
-
-// Option is recovery option.
-type Option func(*options)
-
-type options struct {
-	handler HandlerFunc
-}
-
-// WithHandler with status handler.
-func WithHandler(h HandlerFunc) Option {
-	return func(o *options) {
-		o.handler = h
-	}
-}
-
-// Server is an error middleware.
-func Server(opts ...Option) middleware.Middleware {
-	options := options{
-		handler: errorEncode,
-	}
-	for _, o := range opts {
-		o(&options)
-	}
-	return func(handler middleware.Handler) middleware.Handler {
-		return func(ctx context.Context, req interface{}) (interface{}, error) {
-			reply, err := handler(ctx, req)
-			if err != nil {
-				return nil, options.handler(err)
-			}
-			return reply, nil
-		}
-	}
-}
-
-func errorEncode(err error) error {
-	se := errors.FromError(err)
-	if se == nil {
-		se = errors.New(10400, "", "", err.Error())
-	}
-	return se.GRPCStatus().Err()
-}