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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright © 2023 OpenIM open source community. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package common
  15. import "github.com/pkg/errors"
  16. // msg is a mapping of message.
  17. var msg = map[int]string{
  18. SUCCESS: "success",
  19. ERROR: "error",
  20. INVALID_PARAMS: "request params error",
  21. UNAUTHORIZED: "unauthorized",
  22. FORBIDDEN: "forbidden",
  23. // OpenIM callback code
  24. OPENIM_SERVER_ALLOW_ACTION: "OpenIM allow action",
  25. OPENIM_SERVER_DENY_ACTION: "OpenIM deny action",
  26. // KF service status
  27. KF_RECORD_NOT_FOUND: "kf: record not found",
  28. KF_FILE_SIZE_LIMIT: "kf: file size limit",
  29. KF_INTERNAL_ERROR: "kf: internal error",
  30. }
  31. // internalMsg is a mapping of internal service message.
  32. var internalMsg = map[int]string{
  33. I_INVALID_PARAM: "invalid param",
  34. }
  35. // GetMsg get the message by code.
  36. func GetMsg(code int) string {
  37. m, ok := msg[code]
  38. if ok {
  39. return m
  40. }
  41. return msg[ERROR]
  42. }
  43. // NewError return a new error.
  44. func NewError(code int) error {
  45. return errors.Errorf("%d: %s", code, internalMsg[code])
  46. }