generated from y9vad9/kotlin-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ailure exceptions (#15)
- Loading branch information
Showing
14 changed files
with
166 additions
and
36 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
15 changes: 15 additions & 0 deletions
15
grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt
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,15 @@ | ||
package io.timemates.api.grpc.internal | ||
|
||
/** | ||
* Applies the given transformation function to the exception contained in the `Result` and returns a new `Result` | ||
* with the transformed exception. If the `Result` does not contain an exception, | ||
* it returns the original `Result` unchanged. | ||
* | ||
* @param transform The transformation function to apply to the exception. | ||
* @return A new `Result` with the transformed exception, or the original `Result` if no exception is present. | ||
*/ | ||
internal inline fun <T> Result<T>.mapException(transform: (Throwable) -> Throwable): Result<T> { | ||
val exception = exceptionOrNull() ?: return this | ||
|
||
return Result.failure(transform(exception)) | ||
} |
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
12 changes: 12 additions & 0 deletions
12
sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/AlreadyExistsException.kt
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,12 @@ | ||
package io.timemates.sdk.common.exceptions | ||
|
||
/** | ||
* Exception indicating that an entity already exists. | ||
* | ||
* @param message The detail message for this exception. | ||
* @param cause The cause of this exception. | ||
*/ | ||
public data class AlreadyExistsException( | ||
override val message: String, | ||
override val cause: Throwable? = null | ||
) : TimeMatesException(message, cause) |
9 changes: 9 additions & 0 deletions
9
sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/InternalServerError.kt
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,9 @@ | ||
package io.timemates.sdk.common.exceptions | ||
|
||
/** | ||
* Represents internal failure on server. | ||
*/ | ||
public class InternalServerError( | ||
message: String, | ||
cause: Throwable?, | ||
) : TimeMatesException(message, cause) |
13 changes: 13 additions & 0 deletions
13
sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/InvalidArgumentException.kt
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,13 @@ | ||
package io.timemates.sdk.common.exceptions | ||
|
||
/** | ||
* Represents failure from the server when given argument | ||
* is invalid. | ||
* | ||
* @param message The detail message for this exception. | ||
* @param cause The cause of this exception. | ||
*/ | ||
public data class InvalidArgumentException( | ||
override val message: String, | ||
override val cause: Throwable? | ||
) : TimeMatesException(message, cause) |
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
12 changes: 12 additions & 0 deletions
12
sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/PermissionDeniedException.kt
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,12 @@ | ||
package io.timemates.sdk.common.exceptions | ||
|
||
/** | ||
* Exception indicating that permission is denied. | ||
* | ||
* @param message The detail message for this exception. | ||
* @param cause The cause of this exception. | ||
*/ | ||
public data class PermissionDeniedException( | ||
override val message: String, | ||
override val cause: Throwable? = null | ||
) : TimeMatesException(message, cause) |
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