You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
449B

  1. package transports
  2. import (
  3. "context"
  4. "encoding/json"
  5. "job_risk_third/internal/proto"
  6. "net/http"
  7. )
  8. //自定义一个解码error函数
  9. func MyErrorEncoder(_ context.Context, err error, w http.ResponseWriter) {
  10. res := proto.BaseResponse{
  11. RespCode: 500,
  12. RespMsg: err.Error(),
  13. }
  14. contentType := "application/json,charset=utf-8"
  15. w.Header().Set("content-type", contentType)
  16. w.WriteHeader(200)
  17. body, _ := json.Marshal(res)
  18. w.Write(body)
  19. }