-
Notifications
You must be signed in to change notification settings - Fork 0
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
312119d
commit ffdd6af
Showing
9 changed files
with
49 additions
and
31 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
8 changes: 0 additions & 8 deletions
8
...telse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/exception/ProblemDetailsException.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/utils/HttpClient.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,33 @@ | ||
package no.nav.paw.bekreftelse.api.utils | ||
|
||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.isSuccess | ||
import no.nav.paw.error.exception.ClientResponseException | ||
|
||
private fun HttpStatusCode.hasBody(): Boolean { | ||
return this == HttpStatusCode.BadRequest || | ||
this == HttpStatusCode.Forbidden || | ||
this == HttpStatusCode.NotFound || | ||
this == HttpStatusCode.InternalServerError | ||
} | ||
|
||
suspend fun handleError(response: HttpResponse) { | ||
if (response.status.isSuccess()) { | ||
return | ||
} else if (response.status.hasBody()) { | ||
val error = response.bodyAsText() | ||
throw ClientResponseException( | ||
HttpStatusCode.InternalServerError, | ||
"PAW_HTTP_KLIENT_KALL_FEILET", | ||
"HTTP-kall feilet med status: ${response.status} og body:\n$error" | ||
) | ||
} else { | ||
throw ClientResponseException( | ||
HttpStatusCode.InternalServerError, | ||
"PAW_HTTP_KLIENT_KALL_FEILET", | ||
"HTTP-kall feilet med status: ${response.status}" | ||
) | ||
} | ||
} |
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
10 changes: 5 additions & 5 deletions
10
lib/error-handling/src/main/kotlin/no/nav/paw/error/exception/ErrorCodeAwareException.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package no.nav.paw.error.exception | ||
|
||
open class ErrorCodeAwareException(open val code: String, override val message: String, override val cause: Throwable?) : | ||
Exception(message, cause) { | ||
|
||
constructor(code: String, message: String) : this(code, message, null) | ||
} | ||
open class ErrorCodeAwareException( | ||
open val code: String, | ||
override val message: String, | ||
override val cause: Throwable? = null | ||
) : Exception(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