Skip to content

Commit

Permalink
Manejando excepciones para http response 400x
Browse files Browse the repository at this point in the history
  • Loading branch information
osuka11 committed Jul 28, 2022
1 parent 2983fd9 commit 2659d88
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/src/main/java/com/example/dogapp/api/mainNetworkCall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.example.dogapp.api

import android.util.Log
import com.example.dogapp.R
import com.example.dogapp.UNAUTHORIZED_ERROR_CODE
import com.example.dogapp.api.dto.DogDTOMapper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.HttpException
import java.net.UnknownHostException
/*
No hay que complicarnos mucho aqui, simplemente esa suspend fun(que funcion de manera interna) recibe un lambda
Expand All @@ -28,7 +30,12 @@ suspend fun <T> makeNetworkCall(
ApiResponseStatus.Success(call())
} catch (ex: UnknownHostException) {
ApiResponseStatus.Error(R.string.unknow_host_exception_error)
}catch (e: Exception){

//Esta excepcion es para catchear una excepcion HTTP 400X por parte del cliente
}catch (ex: HttpException){
val errorMessage = if(ex.code() == UNAUTHORIZED_ERROR_CODE ) R.string.wrong_user_or_password else R.string.unknown_error
ApiResponseStatus.Error(errorMessage)
} catch (e: Exception){
//Esta exception la cacheamos en caso de que el la llamada para el signUp regrese cualquiera de estos mensajes

val errorMessage = when(e.message){
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/example/dogapp/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.dogapp.settings

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_list_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/ic_baseline_photo_camera.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path android:fillColor="@android:color/white" android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".settings.SettingsActivity">

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2659d88

Please sign in to comment.