diff --git a/app/src/main/java/com/p_vacho/neat_calendar/activities/LoginActivity.kt b/app/src/main/java/com/p_vacho/neat_calendar/activities/LoginActivity.kt index ecb6fe4..1a3950f 100644 --- a/app/src/main/java/com/p_vacho/neat_calendar/activities/LoginActivity.kt +++ b/app/src/main/java/com/p_vacho/neat_calendar/activities/LoginActivity.kt @@ -78,10 +78,10 @@ class LoginActivity : AppCompatActivity() { .show() } - is LoginResult.UnknownError -> { + is LoginResult.BadCredentials -> { Toast.makeText( this@LoginActivity, - getString(R.string.login_failed_please_try_again), + getString(R.string.login_credentials_invalid), Toast.LENGTH_LONG ).show() } diff --git a/app/src/main/java/com/p_vacho/neat_calendar/activities/RegisterActivity.kt b/app/src/main/java/com/p_vacho/neat_calendar/activities/RegisterActivity.kt index 955479f..33f4811 100644 --- a/app/src/main/java/com/p_vacho/neat_calendar/activities/RegisterActivity.kt +++ b/app/src/main/java/com/p_vacho/neat_calendar/activities/RegisterActivity.kt @@ -86,10 +86,6 @@ class RegisterActivity : AppCompatActivity() { Toast.makeText(this@RegisterActivity, getString(R.string.user_already_exists_please_log_in), Toast.LENGTH_LONG).show() } - is RegisterResult.UnknownError -> { - Toast.makeText(this@RegisterActivity, - getString(R.string.registration_failed_try_again_later), Toast.LENGTH_LONG).show() - } } } } diff --git a/app/src/main/java/com/p_vacho/neat_calendar/util/auth/AuthRepository.kt b/app/src/main/java/com/p_vacho/neat_calendar/util/auth/AuthRepository.kt index 5cf22d5..2ee2a60 100644 --- a/app/src/main/java/com/p_vacho/neat_calendar/util/auth/AuthRepository.kt +++ b/app/src/main/java/com/p_vacho/neat_calendar/util/auth/AuthRepository.kt @@ -15,13 +15,12 @@ sealed class RegisterResult { data class Success(val response: RegisterResponse) : RegisterResult() data class ValidationError(val errorData: com.p_vacho.neat_calendar.api.models.ValidationError) : RegisterResult() data object UserAlreadyExists : RegisterResult() - data class UnknownError(val exception: Throwable) : RegisterResult() } sealed class LoginResult { data object Success : LoginResult() data class ValidationError(val errorData: com.p_vacho.neat_calendar.api.models.ValidationError) : LoginResult() - data class UnknownError(val exception: Throwable) : LoginResult() + data object BadCredentials: LoginResult() } @@ -44,14 +43,15 @@ class AuthRepository(private val tokenManager: TokenManager) { Log.w("API", "Validation error: $validationError") LoginResult.ValidationError(validationError) } - else -> { + 401 -> { Log.w("API", "Login request failed (${e.message()})", e) - LoginResult.UnknownError(e) + LoginResult.BadCredentials + } + else -> { + Log.e("API", "Login request failed (${e.message()})", e) + throw e } } - } catch (e: Exception) { - Log.e("API", "Unexpected error during login", e) - LoginResult.UnknownError(e) } } } @@ -76,13 +76,10 @@ class AuthRepository(private val tokenManager: TokenManager) { RegisterResult.UserAlreadyExists } else -> { - Log.w("API", "Register request failed (${e.message()})", e) - RegisterResult.UnknownError(e) + Log.e("API", "Register request failed (${e.message()})", e) + throw e } } - } catch (e: Exception) { - Log.e("API", "Unexpected error during registration", e) - RegisterResult.UnknownError(e) } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95a4a94..ed0eba5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,10 +62,8 @@ User registered, you may now log in Validation Errors User already exists. Please log in. - Registration failed. Try again later. Please fill in all fields OK - Login failed. Please try again. End time must be after start time User not authenticated. Unable to fetch categories. No more categories to add @@ -101,4 +99,5 @@ Please enter a category name Failed to save category: %1$s At: %1$s + Login credentials invalid \ No newline at end of file