我想打印API消息发送的错误,比如有很多种:电子邮件已经存在,用户名已经存在等等。但这只打印HTTP 400错误请求
fun doSignUp(
firstName: String,
lastName: String,
email: String,
password: String,
deviceId: String
) {
ApiHelper().userSignup(
firstName,
lastName,
email,
password,
"Android",
strAdd)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<UserResponse>{
override fun onComplete() {
Log.d("kb", "onComplete Call")
}
override fun onSubscribe(d: Disposable) {
Log.d("kb", "onSubscribe")
}
override fun onNext(t: UserResponse) {
Toast.makeText(applicationContext,"Please Upload Profile Pic...", Toast.LENGTH_SHORT).show()
val intent = Intent(applicationContext, SignupStep3Activity::class.java)
mPref.setAccessToken(t.data.accessToken)
startActivity(intent)
}
override fun onError(e: Throwable) {
Toast.makeText(applicationContext, e.localizedMessage, Toast.LENGTH_LONG).show()
}
})
}
以下是我的api在错误响应上显示的内容
"message": "Email Already Exists",
"code": 400,
"errors": {
"error_id": "15",
"error_text": "Email Already Exists"
},
"data": []
}
我是科特林的新手,在这里,请原谅我犯的任何错误
在onNext()
中,您需要这样的东西:
when (UserResponse.code()) {
200 -> {//Send appropriate message with intent here}
400 -> {//Send appropriate message with intent here}
401 -> {//Send appropriate message with intent here}
712 -> {//Send appropriate message with intent here}
}