-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate exceptions occurring during client instantiation (#353)
* Auto-close okhttp responses by using Kotlin's Closeable#use * Return more specific ServerInfoRetrievalException if node info fails * Fall back but propagate errors in the end when instantiating client --------- Signed-off-by: PattaFeuFeu <[email protected]>
- Loading branch information
1 parent
8d8da41
commit dab65d4
Showing
18 changed files
with
620 additions
and
455 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
47 changes: 47 additions & 0 deletions
47
bigbone/src/main/kotlin/social/bigbone/api/exception/BigBoneClientInstantiationException.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,47 @@ | ||
package social.bigbone.api.exception | ||
|
||
import okhttp3.Response | ||
import social.bigbone.MastodonClient | ||
import social.bigbone.nodeinfo.entity.NodeInfo | ||
|
||
/** | ||
* Exception thrown if we could not instantiate a [MastodonClient]. Mostly used to wrap other more specific exceptions. | ||
*/ | ||
open class BigBoneClientInstantiationException : Exception { | ||
constructor() : super() | ||
constructor(message: String) : super(message) | ||
constructor(message: String, cause: Throwable?) : super(message, cause) | ||
constructor(cause: Throwable?) : super(cause) | ||
} | ||
|
||
/** | ||
* Exception thrown if we could not retrieve server information during [MastodonClient] instantiation. | ||
*/ | ||
class ServerInfoRetrievalException : BigBoneClientInstantiationException { | ||
constructor(cause: Throwable?) : super(cause) | ||
constructor(message: String, cause: Throwable?) : super(message, cause) | ||
constructor(response: Response, message: String? = null) : super( | ||
message = "${message ?: ""}${response.message}" | ||
) | ||
} | ||
|
||
/** | ||
* Exception thrown if we could not successfully get the [NodeInfo] server URL during [MastodonClient] instantiation. | ||
*/ | ||
class ServerInfoUrlRetrievalException( | ||
response: Response, | ||
message: String? = null | ||
) : | ||
BigBoneClientInstantiationException( | ||
message = "${message ?: ""}${response.message}" | ||
) | ||
|
||
/** | ||
* Exception thrown if we could not retrieve the instance version of a Mastodon server during [MastodonClient] instantiation. | ||
*/ | ||
class InstanceVersionRetrievalException : BigBoneClientInstantiationException { | ||
constructor(cause: Throwable?) : super(cause) | ||
constructor(response: Response, message: String? = null) : super( | ||
message = "${response.code} – ${message ?: ""}${response.message}" | ||
) | ||
} |
Oops, something went wrong.