Skip to content

Commit

Permalink
Issues #287 chore: db Result 를 CustomException 으로 처리하게 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Feb 8, 2023
1 parent cdeeffa commit 9499679
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lighthouse.database.converter
package com.lighthouse.data.database.converter

import android.graphics.Rect
import androidx.core.text.isDigitsOnly
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lighthouse.database.converter
package com.lighthouse.data.database.converter

import android.net.Uri
import androidx.room.TypeConverter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.data.database.exception

class DBDeleteException(message: String = "데이터 Delete 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.data.database.exception

class DBInsertException(message: String = "데이터 Insert 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.data.database.exception

class DBNotFoundException(message: String = "데이터를 찾을 수 없습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.data.database.exception

class DBSelectException(message: String = "데이터 Select 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.data.database.exception

class DBUpdateException(message: String = "데이터 Update 에 실패 했습니다.") : Exception(message)

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package com.lighthouse.data.database.ext

import com.lighthouse.beep.model.exception.db.DeleteException
import com.lighthouse.beep.model.exception.db.InsertException
import com.lighthouse.beep.model.exception.db.NotFoundException
import com.lighthouse.beep.model.exception.db.SelectException
import com.lighthouse.beep.model.exception.db.UpdateException
import com.lighthouse.beep.model.result.DbResult
import com.lighthouse.data.database.exception.DeleteException
import com.lighthouse.data.database.exception.InsertException
import com.lighthouse.data.database.exception.NotFoundException
import com.lighthouse.data.database.exception.SelectException
import com.lighthouse.data.database.exception.UpdateException
import com.lighthouse.data.database.exception.DBDeleteException
import com.lighthouse.data.database.exception.DBInsertException
import com.lighthouse.data.database.exception.DBNotFoundException
import com.lighthouse.data.database.exception.DBSelectException
import com.lighthouse.data.database.exception.DBUpdateException

internal inline fun <T, R> T.runCatchingDB(block: T.() -> R): DbResult<R> {
return try {
DbResult.Success(block())
} catch (e: NotFoundException) {
DbResult.NotFoundError(e)
} catch (e: SelectException) {
DbResult.SelectError(e)
} catch (e: InsertException) {
DbResult.InsertError(e)
} catch (e: DeleteException) {
DbResult.DeleteError(e)
} catch (e: UpdateException) {
DbResult.UpdateError(e)
} catch (e: DBNotFoundException) {
DbResult.Failure(NotFoundException(e.message))
} catch (e: DBSelectException) {
DbResult.Failure(SelectException(e.message))
} catch (e: DBInsertException) {
DbResult.Failure(InsertException(e.message))
} catch (e: DBDeleteException) {
DbResult.Failure(DeleteException(e.message))
} catch (e: DBUpdateException) {
DbResult.Failure(UpdateException(e.message))
} catch (e: Throwable) {
DbResult.Failure(e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lighthouse.data.database.mapper.brand

import com.lighthouse.beep.model.location.Dms

internal fun combineSectionId(x: Dms, y: Dms, brandName: String): String {
return "${x.dmsToString()}_${y.dmsToString()}_${brandName.lowercase()}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.beep.model.exception.db

class InsertException(message: String? = "데이터 Insert 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.beep.model.exception.db

class NotFoundException(message: String? = "데이터를 찾을 수 없습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.beep.model.exception.db

class SelectException(message: String? = "데이터 Select 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lighthouse.beep.model.exception.db

class UpdateException(message: String? = "데이터 Update 에 실패 했습니다.") : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ sealed class DbResult<out T> {
object Empty : DbResult<Nothing>()
data class Failure(val throwable: Throwable) : DbResult<Nothing>()

data class NotFoundError(val throwable: Throwable) : DbResult<Nothing>()
data class SelectError(val throwable: Throwable) : DbResult<Nothing>()
data class InsertError(val throwable: Throwable) : DbResult<Nothing>()
data class UpdateError(val throwable: Throwable) : DbResult<Nothing>()
data class DeleteError(val throwable: Throwable) : DbResult<Nothing>()
val isSuccess: Boolean get() = this is Success

val isFailure: Boolean get() = this is Failure
}

0 comments on commit 9499679

Please sign in to comment.