error_code.go 674 B

12345678910111213141516171819202122232425262728
  1. package consts
  2. import "github.com/go-redis/redis/v8"
  3. var RedisNil = redis.Nil
  4. var errorCodeToastMap = map[int32]string{}
  5. const DefaultToast = ""
  6. const ErrorSuccess int32 = 0
  7. const ErrorNotLogin int32 = 4001
  8. const ErrorParamCheck int32 = 5001
  9. const ErrorInternal int32 = 5001
  10. func init() {
  11. errorCodeToastMap[ErrorSuccess] = "请求成功"
  12. errorCodeToastMap[ErrorNotLogin] = "请登录后操作"
  13. errorCodeToastMap[ErrorParamCheck] = "参数有误"
  14. errorCodeToastMap[ErrorInternal] = "网络错误"
  15. }
  16. func GetErrorToast(errorCode int32) string {
  17. toast, contain := errorCodeToastMap[errorCode]
  18. if contain {
  19. return toast
  20. }
  21. return "网络错误,请稍后再试"
  22. }