# Handle Structured Errors

This section deals with converting SDK failures into structured `OfflineRegionError` values and use stable error codes for localized messages, logging, and diagnostics. Regional Offline suspend APIs use `Result` to return errors. First convert the throwable to _OfflineRegionError_, then handle it by subtype or stable `errorCode`:

```kotlin
private fun renderError(throwable: Throwable) {
    val error = OfflineRegionError.from(throwable)
    when (error) {
        is OfflineRegionError.Network ->
            showLocalizedMessage(R.string.offline_network_error)
        is OfflineRegionError.Storage ->
            showLocalizedMessage(R.string.offline_storage_error)
        is OfflineRegionError.StyleNotCached ->
            showLocalizedMessage(R.string.offline_resources_not_ready)
        is OfflineRegionError.NoInstalledRegions ->
            showLocalizedMessage(R.string.offline_no_installed_region)
        is OfflineRegionError.NotInitialized ->
            showLocalizedMessage(R.string.offline_not_initialized)
        is OfflineRegionError.UnsupportedTileServer ->
            showLocalizedMessage(R.string.offline_tomtom_required)
        is OfflineRegionError.Unknown ->
            showLocalizedMessage(R.string.offline_unknown_error)
    }

    logOfflineFailure(error.errorCode, error)
}
```

Stable error codes:

| Type | errorCode |
| --- | --- |
| _StyleNotCached_ | `STYLE_NOT_CACHED` |
| _NoInstalledRegions_ | `NO_INSTALLED_REGIONS` |
| _Storage_ | `STORAGE` |
| _Network_ | `NETWORK` |
| _Unknown_ | `UNKNOWN` |
| _NotInitialized_ | `NOT_INITIALIZED` |
| _UnsupportedTileServer_ | `UNSUPPORTED_TILE_SERVER` |

`message` and the download progress field `errorMessage` are diagnostic text. They are not machine-readable protocols and must not be displayed directly as user-facing copy.
