1 Star 0 Fork 212

homeleaf / maple

forked from Hao / maple 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
status-code.txt 3.45 KB
一键复制 编辑 原始数据 按行查看 历史
Hao 提交于 2017-07-14 09:12 . Initial commit
状态码的约定:
除了Token验证失败返回了HTTP状态码外,其他的异常、错误、逻辑判断返回的状态码都是自定义的
通用的响应结果如下:
{
"body": {
"username": "admin"
},
"code": 200,
"message": "ok",
"now": "2017-04-06 15:42:20"
}
code = 状态码
message = 信息,有错误或异常时即为错误信息(客户端不应该直接显示该message,而应该自己根据code的业务标识判断,返回友好的提示给用户)
now = 服务器当前时间
body = 实际响应内容,有错误或异常时为null
在base模块中的StatusCode定义了一些常用的状态码,可以直接使用。
但其他业务模块的状态码不应该定义在base模块中,也就是说base模块是不负责处理业务
各个不同的业务模块,需要自行按照StatusCode中的规格定义,如system模块中的SystemError
业务模块的状态码约定:
/*
错误码格式说明(示例:202001),1为系统级错误,2为业务逻辑错误
--------------------------------------------------------------------
服务级错误(1为系统级错误) 服务模块代码(即业务模块标识) 具体错误代码
2 02 001
--------------------------------------------------------------------
*/
//2 00 001 释义: 00 = System 业务模块标识,001为具体的错误代码
约定:
00 = system模块
01 =
02 =
03 =
04 =
....
开发人员应该统一规范和标准,约定如何定义各模块的状态码标识
常用的HTTP状态码:
Response Class HTTP Status Code Symbol
消息
100 :continue
101 :switching_protocols
102 :processing
成功
200 :ok
201 :created
202 :accepted
203 :non_authoritative_information
204 :no_content
205 :reset_content
206 :partial_content
207 :multi_status
208 :already_reported
226 :im_used
重定向
300 :multiple_choices
301 :moved_permanently
302 :found
303 :see_other
304 :not_modified
305 :use_proxy
306 :reserved
307 :temporary_redirect
308 :permanent_redirect
客户端错误
400 :bad_request
401 :unauthorized
402 :payment_required
403 :forbidden
404 :not_found
405 :method_not_allowed
406 :not_acceptable
407 :proxy_authentication_required
408 :request_timeout
409 :conflict
410 :gone
411 :length_required
412 :precondition_failed
413 :request_entity_too_large
414 :request_uri_too_long
415 :unsupported_media_type
416 :requested_range_not_satisfiable
417 :expectation_failed
422 :unprocessable_entity
423 :locked
424 :failed_dependency
426 :upgrade_required
428 :precondition_required
429 :too_many_requests
431 :request_header_fields_too_large
服务端错误
500 :internal_server_error
501 :not_implemented
502 :bad_gateway
503 :service_unavailable
504 :gateway_timeout
505 :http_version_not_supported
506 :variant_also_negotiates
507 :insufficient_storage
508 :loop_detected
510 :not_extended
511 :network_authentication_required
200 ok - 成功返回状态,对应,GET,PUT,PATCH,DELETE.
201 created - 成功创建。
304 not modified - HTTP缓存有效。
400 bad request - 请求格式错误。
401 unauthorized - 未授权。
403 forbidden - 鉴权成功,但是该用户没有权限。
404 not found - 请求的资源不存在
405 method not allowed - 该http方法不被允许。
410 gone - 这个url对应的资源现在不可用。
415 unsupported media type - 请求类型错误。
422 unprocessable entity - 校验错误时用。
429 too many request - 请求过多。
Java
1
https://gitee.com/homeleaf/maple.git
git@gitee.com:homeleaf/maple.git
homeleaf
maple
maple
master

搜索帮助