Files
rider-pro-android-app/app/src/main/java/com/aiosman/riderpro/data/Exception.kt
AllenTom 025f66ca83 新增邮箱注册页面表单校验
新增邮箱注册页面表单校验,包括:
- 邮箱格式校验
- 密码格式校验(至少8位,
包含大小写字母和数字)
- 确认密码校验
- 服务条款和推广信息勾选校验

新增错误提示,包括:
- 邮箱格式错误
- 密码格式错误
- 确认密码不一致
- 未勾选服务条款
- 未勾选推广信息

优化
用户体验,包括:
- 使用 CheckboxWithLabel 组件优化勾选框样式
- 使用字符串资源
- 调整页面布局
2024-09-06 15:34:27 +08:00

43 lines
974 B
Kotlin

package com.aiosman.riderpro.data
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import okhttp3.ResponseBody
/**
* 错误返回
*/
class ServiceException(
override val message: String,
val code: Int? = 0,
val data: Any? = null,
val error: String? = null,
val name: String? = null,
) : Exception(
message
)
data class ApiErrorResponse(
@SerializedName("code")
val code: Int?,
@SerializedName("error")
val error: String?,
@SerializedName("message")
val name: String?,
) {
fun toServiceException(): ServiceException {
return ServiceException(
message = error ?: name ?: "",
code = code,
error = error,
name = name
)
}
}
fun parseErrorResponse(errorBody: ResponseBody?): ApiErrorResponse? {
return errorBody?.let {
val gson = Gson()
gson.fromJson(it.charStream(), ApiErrorResponse::class.java)
}
}