-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ec8060
commit 0f7b90e
Showing
6 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.bedrest.app.utils | ||
|
||
import com.bedrest.app.App | ||
import com.bedrest.app.R | ||
import com.bedrest.app.data.model.BaseResponse | ||
import com.bedrest.app.utils.StringUtils.stringSuspending | ||
import com.google.gson.Gson | ||
import retrofit2.HttpException | ||
|
||
object ErrorUtils { | ||
|
||
suspend fun Exception.getError(): String { | ||
return when (this) { | ||
is HttpException -> { | ||
val errorResponse: BaseResponse<*> = Gson().fromJson( | ||
response()?.errorBody()?.stringSuspending(), | ||
BaseResponse::class.java | ||
) | ||
errorResponse.error | ||
} | ||
else -> App.INSTANCE.applicationContext.getString(R.string.error_response) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters