-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement detailed API error handling in PackageSearchApiClient
This commit introduces the PackageSearchApiException class to provide extensive details on API errors. Additionally, an HttpCallValidator has been added to verify client responses, alongside the SerializableHttpStatusCode class which allows for user-friendly presentation of HTTP status codes.
- Loading branch information
Showing
3 changed files
with
87 additions
and
12 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
23 changes: 23 additions & 0 deletions
23
...rc/commonMain/kotlin/org/jetbrains/packagesearch/api/v3/http/PackageSearchApiException.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,23 @@ | ||
package org.jetbrains.packagesearch.api.v3.http | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
public data class PackageSearchApiException( | ||
val serverMessage: String, | ||
val request: SerializableHttpRequest, | ||
val statusCode: SerializableHttpStatusCode, | ||
val remoteStackTrace: List<String> = emptyList(), | ||
) : Throwable() { | ||
override val message: String | ||
get() = buildString { | ||
append("Error response for endpoint ${request.method} ${request.url}:") | ||
appendLine("- Headers:") | ||
request.headers.forEach { appendLine(" -> ${it.key}: ${it.value.joinToString()}") } | ||
appendLine("- Status code: ${statusCode.value} ${statusCode.description}") | ||
if (remoteStackTrace.isNotEmpty()) { | ||
append("- Remote stack trace:") | ||
remoteStackTrace.forEach { appendLine(" $it") } | ||
} | ||
} | ||
} |
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