Skip to main content

Error Scenarios

Certainly! Error messages play a crucial role in helping users understand and resolve issues they encounter while using an application. While triggering any event if anything goes wrong you would be receiving the error within your result object i.e KssIdpResultObject.

The following details specify under what circumstances and which specific errors would be triggered, enabling users to implement appropriate handling for both iOS and Android.

Swift/iOS


public struct KssIdpResultObject {
public let status: KssIdpStatus
public let userId: String
public let traceContext: TraceContext?
}



public enum KssIdpStatus {
case success(message: String, resultStatus: ResultStatus? = .success )
case eventFailed(status: KSMEventStatusType, errorDescription: String, line: Int)
case requestFailed(status: KSMCreateHttpCommonRequestStatus, httpStatus: Int, errorModel: KssIdpErrorModel, line: Int)
case biometricError(errorCode: Int, errorDescription: String)
}


public struct KssIdpErrorModel {
public let subsystem: Int
public let code: String
public let description: String
public let parameters: [String: String]
}

KssIdpStatus: eventFailed

This status would be retrieved when there is any error from MC(Master Controller). For instance, it might occur if the application fails to receive the GetAstClientDataResultEvent in response to the GetAstClientDataEvent, Another potential scenario is when the status obtained from the Master Controller result event is not success.

KssIdpStatus: requestFailed

This status would be retrieved when the result status of the CreateHttpCommonRequestEvent is not successful or when the data becomes null upon parsing the responseBody of the CreateHttpCommonRequestResultEvent.


Android/Kotlin


data class KssIdpResultObject(
val status: KssIdpStatus,
val kssIdpError: KssIdpResult?
)

enum class KssIdpStatus {
SUCCESS,
EVENT_FAILED,
REQUEST_FAILED
}

KssIdpResult can be either of below mentioned types:

  1. KssIdpEventFailed
  2. KssIdpRequestFailed

KssIdpEventFailed

This error type is typically triggered when there is any error from MC(Master Controller). For instance, it might occur if the application fails to receive the GetAstClientDataResultEvent in response to the GetAstClientDataEvent, Another potential scenario is when the status obtained from the Master Controller result event is not success.

In this scenario, the status would be retrieved as EVENT_FAILED within the KssIdpResultObject.


class KssIdpEventFailed(
val status : StatusType,
val errorDescription: String,
val errorCode: String
): KssIdpResult() {}

KssIdpRequestFailed

This error type is typically triggered when the result status of the CreateHttpCommonRequestEvent is not successful or when the data becomes null upon parsing the responseBody of the CreateHttpCommonRequestResultEvent.

In this scenario, the status would be retrieved as REQUEST_FAILED within the KssIdpResultObject.


class KssIdpRequestFailed(
val status: CreateHttpCommonRequestResultEvent.Status,
val httpStatus: Int,
val error: KssIdpErrorModel
): KssIdpResult()

KssIdpErrorModel

This model contains additional information about what went wrong when sending a KssIdp Request.


data class KssIdpErrorModel(
var subSystem: String,
var code: String,
var description: String,
var parameters: MutableMap<String, String>
)

Example use

We suggest to first check the KssIdpStatus of the received KssIdpResultObject. Then cast the contained KssIdpResult to KssIdpEventFailed in case of KssIdpStatus.EVENT_FAILED, or to KssIdpRequestFailed in case of KssIdpStatus.REQUEST_FAILED.


override fun onResultReceived(result: KssIdpResultObject) {
when (result.status) {
KssIdpStatus.SUCCESS -> {}
KssIdpStatus.EVENT_FAILED -> {
val kssIdpEventFailed = (result.kssIdpError as KssIdpEventFailed)

val errorDescription: String = kssIdpEventFailed.errorDescription
val errorCode: String = kssIdpEventFailed.errorCode
val status: com.kobil.wrapper.events.StatusType = kssIdpEventFailed.status
}
KssIdpStatus.REQUEST_FAILED -> {
val kssIdpRequestFailedError = (result.kssIdpError as KssIdpRequestFailed)

val kssIdpErrorModel: KssIdpErrorModel = kssIdpRequestFailedError.error
val httpStatus: Int = kssIdpRequestFailedError.httpStatus
val status: com.kobil.wrapper.events.CreateHttpCommonRequestResultEvent.Status = kssIdpRequestFailedError.status

// kssIdpErrorModel contains additional information about what went wrong with the KssIdp Request.
kssIdpErrorModel.subSystem
kssIdpErrorModel.code
kssIdpErrorModel.description
kssIdpErrorModel.parameters
}
}
}


private func handleNewResult(newResultObject: KssIdpResultObject) {
let actionResult: ActionResult
let status = newResultObject.status
let event: KSMSetAuthorisationCodeResultEvent
switch status {
case .success(let message, let resultStatus):
event = resultStatus == .letter_sent_success ? KSMSetAuthorisationCodeResultEvent(status: .KSMFAILED): KSMSetAuthorisationCodeResultEvent(status: .KSMOK)
let suc = resultStatus == .letter_sent_success ? false : true
if(!suc) {
actionResult = ActionResult(title: "kssidp", success: suc, error: message, duration: 0, event: event, onActionCompleted: {
appCoordinator.navigateToRootViewController()
})
} else {
actionResult = ActionResult(title: "kssidp", success: suc, error: nil, duration: 0, event: event)
}
EnableAuthenticationModeModel().updateCurrent(mode: AuthenticationModeModel().current)
case let .eventFailed(status, errorDescription, line):
event = KSMSetAuthorisationCodeResultEvent(status: status)
actionResult = ActionResult(title: "kssIdpModel.error.idpErrorTitle".localized(table: localizedTable),
success: false,
error: nil,
duration: 0,
event: event)
case let .requestFailed(httpCommonRequestStatus, httpStatus, errorModel, line):
let errorText = handleRequestFailure(status: httpCommonRequestStatus, httpStatus: httpStatus, errorModel: errorModel)
event = KSMSetAuthorisationCodeResultEvent(status: .KSMFAILED)
actionResult = ActionResult(title: "kssIdpModel.error.idpErrorTitle".localized(table: localizedTable),
success: false,
error: errorText.localized(table: localizedTable),
duration: 0,
event: event,
onActionCompleted: {
appCoordinator.navigateToRootViewController()
})
case let .biometricError(errorCode, errorDescription):
event = KSMSetAuthorisationCodeResultEvent(status: .KSMFAILED)
actionResult = ActionResult(title: "kssIdpModel.error.idpErrorTitle".localized(table: localizedTable),
success: false,
error: errorDescription,
duration: 0,
event: event)
@unknown default:
event = KSMSetAuthorisationCodeResultEvent(status: .KSMFAILED)
actionResult = ActionResult(title: "kssIdpModel.error.idpErrorTitle".localized(table: localizedTable),
success: false,
error: "Unexpected error",
duration: 0,
event: event)
}
}