Fix errors in api calls, move base url to gradle properties
This commit is contained in:
parent
0f791cc642
commit
dfa9abc4b9
@ -19,7 +19,7 @@ android {
|
|||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
buildConfigField("String", "API_BASE_URL", gradleLocalProperties(projectDir, providers).getProperty("API_BASE_URL"))
|
buildConfigField("String", "API_BASE_URL", project.property("API_BASE_URL").toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
1
app/app/gradle.properties
Normal file
1
app/app/gradle.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
API_BASE_URL="https://easyeat.mercantec.tech"
|
@ -31,7 +31,10 @@ class RegisterActivity : AppCompatActivity() {
|
|||||||
try {
|
try {
|
||||||
register(email, username, password)
|
register(email, username, password)
|
||||||
} catch (e: ApiRequestException) {
|
} catch (e: ApiRequestException) {
|
||||||
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
|
runOnUiThread {
|
||||||
|
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
return@thread
|
return@thread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,8 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
|
|||||||
|
|
||||||
throw ApiRequestException(error.message, null)
|
throw ApiRequestException(error.message, null)
|
||||||
} catch (e: SerializationException) {
|
} catch (e: SerializationException) {
|
||||||
|
if (e.message != null)
|
||||||
|
Log.e("EasyEat", e.message!!)
|
||||||
Log.e("EasyEat", response.body)
|
Log.e("EasyEat", response.body)
|
||||||
|
|
||||||
throw ApiRequestException("Request failed with HTTP status code ${response.code}", e)
|
throw ApiRequestException("Request failed with HTTP status code ${response.code}", e)
|
||||||
@ -68,6 +70,8 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
|
|||||||
try {
|
try {
|
||||||
return Json.decodeFromString<Res>(response.body)
|
return Json.decodeFromString<Res>(response.body)
|
||||||
} catch (e: SerializationException) {
|
} catch (e: SerializationException) {
|
||||||
|
if (e.message != null)
|
||||||
|
Log.e("EasyEat", e.message!!)
|
||||||
Log.e("EasyEat", response.body)
|
Log.e("EasyEat", response.body)
|
||||||
|
|
||||||
throw ApiRequestException("Failed to parse response: $response", e)
|
throw ApiRequestException("Failed to parse response: $response", e)
|
||||||
|
@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
|
|||||||
data class LoginRequest(val emailUsr: String, val password: String)
|
data class LoginRequest(val emailUsr: String, val password: String)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LoginResponse(val token: String, val username: String, val id: Int, val refreshToken: String)
|
data class LoginResponse(val token: String, val userName: String, val id: Int, val refreshToken: String)
|
||||||
|
|
||||||
fun login(email: String, password: String) {
|
fun login(email: String, password: String) {
|
||||||
val request = LoginRequest(email, password)
|
val request = LoginRequest(email, password)
|
||||||
|
Loading…
Reference in New Issue
Block a user