1.对于API结果返回,定义BaseResult 类

拥有success,errorCode,errorMsg个3个基本参数,success使用Boolean类型,errorCode使用Integer类型,errorMsg使用String类型

对于success,false表示接口请求失败,true表示接口请求成功。

对于errorCode,当success=true时为0,其他请参阅ABBCCC格式错误码。

对于errorMsg,当success=true时为null,其他情况不为null。

如下图所示

Java服务器端 API 错误码设计总结

2.错误码格式定义

统一格式:A-BB-CCC,6位长度整形int。

A:代表错误级别,1表示系统级错误,2表示服务级错误。

BB:代表错误项目或者模块号,从00开始。

CCC:具体错误编号,自增,从001开始。

相关文章:

  • 2021-10-19
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-11-30
  • 2022-12-23
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-02-10
  • 2021-12-14
相关资源
相似解决方案