1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2022 Yansen Zhang
  3. * wxcomponent is licensed under Mulan PSL v2.
  4. * You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. * You may obtain a copy of Mulan PSL v2 at:
  6. * http://license.coscl.org.cn/MulanPSL2
  7. * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. * See the Mulan PSL v2 for more details.
  11. **/
  12. package errors
  13. import "fmt"
  14. // Error 通用错误
  15. type Error struct {
  16. Code int `json:"errcode"`
  17. Message string `json:"errmsg"`
  18. }
  19. func (e *Error) Error() string {
  20. return fmt.Sprintf("[%d] - %s", e.Code, e.Message)
  21. }
  22. func New(msg string) error {
  23. return &Error{
  24. Code: -100,
  25. Message: msg,
  26. }
  27. }