Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Coordinator(
}
}
} catch (error: SPError) {
throw LoadMessagesException(causedBy = error)
throw LoadMessagesException(cause = error)
}
storeLegislationConsent(userData = userData)
persistState()
Expand Down Expand Up @@ -1007,7 +1007,7 @@ class Coordinator(
IOS14, SPCampaignType.Unknown -> {}
}
} catch (error: SPError) {
throw ReportActionException(causedBy = error, actionType = action.type, campaignType = action.campaignType)
throw ReportActionException(cause = error, actionType = action.type, campaignType = action.campaignType)
} finally {
storeLegislationConsent(userData = userData)
persistState()
Expand Down Expand Up @@ -1044,7 +1044,7 @@ class Coordinator(
legIntCategories = legIntCategories
))
} catch (error: SPError) {
throw PostCustomConsentGDPRException(causedBy = error)
throw PostCustomConsentGDPRException(cause = error)
}
}

Expand All @@ -1065,7 +1065,7 @@ class Coordinator(
legIntCategories = legIntCategories
))
} catch (error: SPError) {
throw DeleteCustomConsentGDPRException(causedBy = error)
throw DeleteCustomConsentGDPRException(cause = error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package com.sourcepoint.mobile_core.models
open class SPError(
val code: String = "sp_metric_generic_mobile-core_error",
val description: String = "Something went wrong in the Mobile Core",
val causedBy: SPError? = null,
override val cause: Throwable? = null,
open val campaignType: SPCampaignType? = null
): Exception(description)
): Throwable(description) {
companion object {
fun castToSPError(error: Throwable): SPError =
error as? SPError ?:
SPError(cause = error, description = error.message ?: "Something went wrong in the Mobile Core")
}
}

open class SPUnknownNetworkError(path: String): SPError(
code = "sp_metric_unknown_network_error_${path}",
Expand Down Expand Up @@ -52,27 +58,55 @@ open class InvalidPropertyNameError(propertyName: String): SPError(
open class ReportActionException(
actionType: SPActionType,
campaignType: SPCampaignType?,
causedBy: SPError
cause: SPError
): SPError(
code = "sp_metric_report_action_exception_${campaignType?.name}_${actionType.name}",
description = "Unable to report ${actionType.name} action for campaign ${campaignType?.name} due to ${causedBy.description}",
causedBy = causedBy
description = "Unable to report ${actionType.name} action for campaign ${campaignType?.name} due to ${cause.description}",
cause = cause
)

open class LoadMessagesException(causedBy: SPError): SPError(
open class LoadMessagesException(cause: SPError): SPError(
code = "sp_metric_load_messages",
description = "Unable to loadMessages due to ${causedBy.description}",
causedBy = causedBy
description = "Unable to loadMessages due to ${cause.description}",
cause = cause
)

open class PostCustomConsentGDPRException(causedBy: SPError): SPError(
open class PostCustomConsentGDPRException(cause: SPError): SPError(
code = "sp_metric_post_custom_consent_gdpr",
description = "Unable to post CustomConsentGDPR due to ${causedBy.description}",
causedBy = causedBy
description = "Unable to post CustomConsentGDPR due to ${cause.description}",
cause = cause
)

open class DeleteCustomConsentGDPRException(causedBy: SPError): SPError(
open class DeleteCustomConsentGDPRException(cause: SPError): SPError(
code = "sp_metric_delete_custom_consent_gdpr",
description = "Unable to delete CustomConsentGDPR due to ${causedBy.description}",
causedBy = causedBy
description = "Unable to delete CustomConsentGDPR due to ${cause.description}",
cause = cause
)

open class InvalidRequestAPIError(cause: Throwable, endpoint: InvalidAPICode): SPError (
code = "sp_metric_invalid_response_api${endpoint.type}",
description = "The SDK got an unexpected response from ${endpoint.name}",
cause = castToSPError(cause)
)

enum class InvalidAPICode(val type: String) {
META_DATA("_meta-data"),
CONSENT_STATUS("_consent-status"),
PV_DATA("_pv-data"),
MESSAGES("_messages"),
ERROR_METRICS("_error-metrics"),
CCPA_ACTION("_CCPA-action"),
GDPR_ACTION("_GDPR-action"),
USNAT_ACTION("_USNAT-action"),
GLOBALCMP_ACTION("_GLOBALCMP-action"),
PREFERENCES_ACTION("_PREFERENCES-action"),
IDFA_STATUS( "_IDFA-status"),
CHOICE_ALL("_choice-all"),
CUSTOM_CONSENT("custom-consent-GDPR"),
DELETE_CUSTOM_CONSENT("_delete-custom-consent-GDPR"),
CCPA_PRIVACY_MANAGER("_CCPA-privacy-manager"),
GDPR_PRIVACY_MANAGER("_GDPR-privacy-manager"),
CCPA_MESSAGE("_CCPA-message"),
GDPR_MESSAGE("_GDPR-message"),
EMPTY("")
}
Loading