Add InvalidSymbolException to hebe
This commit is contained in:
parent
8726501d8b
commit
62d5ff05ef
3 changed files with 31 additions and 15 deletions
|
@ -0,0 +1,5 @@
|
|||
package io.github.wulkanowy.sdk.hebe.exception
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
class InvalidSymbolException : IOException()
|
|
@ -2,11 +2,14 @@ package io.github.wulkanowy.sdk.hebe.repository
|
|||
|
||||
import io.github.wulkanowy.sdk.hebe.ApiRequest
|
||||
import io.github.wulkanowy.sdk.hebe.ApiResponse
|
||||
import io.github.wulkanowy.sdk.hebe.exception.InvalidSymbolException
|
||||
import io.github.wulkanowy.sdk.hebe.getEnvelopeOrThrowError
|
||||
import io.github.wulkanowy.sdk.hebe.register.RegisterRequest
|
||||
import io.github.wulkanowy.sdk.hebe.register.RegisterResponse
|
||||
import io.github.wulkanowy.sdk.hebe.register.StudentInfo
|
||||
import io.github.wulkanowy.sdk.hebe.service.RegisterService
|
||||
import retrofit2.HttpException
|
||||
import java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
|
||||
|
||||
internal class RegisterRepository(private val service: RegisterService) {
|
||||
|
||||
|
@ -33,7 +36,8 @@ internal class RegisterRepository(private val service: RegisterService) {
|
|||
firebaseToken: String,
|
||||
pin: String,
|
||||
token: String,
|
||||
): ApiResponse<RegisterResponse> = service.registerDevice(
|
||||
): ApiResponse<RegisterResponse> = runCatching {
|
||||
service.registerDevice(
|
||||
ApiRequest(
|
||||
certificateId = certificateId,
|
||||
firebaseToken = firebaseToken,
|
||||
|
@ -46,6 +50,13 @@ internal class RegisterRepository(private val service: RegisterService) {
|
|||
),
|
||||
),
|
||||
)
|
||||
}.onFailure {
|
||||
if (it is HttpException && it.code() == HTTP_INTERNAL_ERROR) {
|
||||
if ("ArgumentException" in it.response()?.errorBody()?.string().orEmpty()) {
|
||||
throw InvalidSymbolException()
|
||||
}
|
||||
}
|
||||
}.getOrThrow()
|
||||
|
||||
suspend fun getStudentInfo(): List<StudentInfo> {
|
||||
return service.getStudentsInfo().envelope!!
|
||||
|
|
|
@ -32,9 +32,9 @@ class HebeRemoteTest {
|
|||
fun `register device`() = runTest {
|
||||
val res = hebe.register(
|
||||
firebaseToken = "",
|
||||
token = "3S1JDDR",
|
||||
pin = "212343",
|
||||
symbol = "gminanowosolna",
|
||||
token = "FK11234",
|
||||
pin = "123456",
|
||||
symbol = "powiatwulkanowy",
|
||||
)
|
||||
assertTrue(res.privatePem.isNotEmpty())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue