Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RESTFul App处理逻辑
//请求成功返回2XX
if (statusCode.startWith('2')) {
//请求成功,处理业务
} else {
//5XX错误,服务器有问题
if (statusCode.startWith('5')) {
//响应格式不定,显示网络错误或未知错误给用户
} elseif (statusCode.startWith('4')) {
//4XX错误,输入有问题
//4XX错误后端必须保证错误格式
res = json_decode(responseBody)
switch (res.errors[0].message) {
//客户端需要处理的异常分支
case 'ERR_USER_MOBILE_CAPTCHA_CHECK_FAILED':
//验证码错误
break
//客户端无法预料的异常分支
default:
//打印错误信息
print res.errors[0].message_human
}
} else {
//未知错误
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.