Error reference
SDK methods throw two error types: ChatCenterUIError (chat operations) and ChatCenterUISendMessageError (message sending).
Chat errors (ChatCenterUIError)
Thrown by chat-related methods.
| Error | Description | Cause | Recommendation |
|---|---|---|---|
.userNotAuthorized | The user is not authorized | The method was called before authorize(user:) or after logout() / deauthorizeUser() | Call authorize(user:) before using the method |
.chatNotOpened | The chat screen is not open, or userInfo is empty | handleNotification(userInfo:) was called while the chat is not displayed, or the userInfo dictionary is empty | This is expected behavior. Use getChat(userInfo:) to open the chat with the notification context. See Notifications for details |
Which methods throw ChatCenterUIError
| Method | Possible errors |
|---|---|
getChat(userInfo:) | .userNotAuthorized |
logout() | .userNotAuthorized |
getUnreadMessagesCount(completion:) | .userNotAuthorized |
handleNotification(userInfo:) | .chatNotOpened |
Handling example
do {
let chatController = try chatCenterSDK.getChat()
navigationController?.pushViewController(chatController, animated: true)
} catch ChatCenterUIError.userNotAuthorized {
// User is not authorized — show the login screen
showLoginScreen()
} catch {
print("Unexpected error: \(error)")
}
The SDK does not expose a public isAuthorized() or currentUser() method. Track the authorization state on the application side: set a flag on a successful authorize(user:) and clear it on logout() / deauthorizeUser(). Or catch .userNotAuthorized via do/catch (see the example above).
do {
try chatCenterSDK.handleNotification(userInfo: userInfo)
} catch ChatCenterUIError.chatNotOpened {
// Chat is not open — open it with the notification context
do {
let chatController = try chatCenterSDK.getChat(userInfo: userInfo)
navigationController?.pushViewController(chatController, animated: true)
} catch {
print("Error opening chat: \(error)")
}
} catch {
print("Error handling notification: \(error)")
}
Message sending errors (ChatCenterUISendMessageError)
Thrown by the send(message:) method.
| Error | Description | Cause | Recommendation |
|---|---|---|---|
.userNotAuthorized | The user is not authorized | authorize() was not called | Call authorize(user:) before sending |
.webSocketNotActive | The WebSocket connection is not active | Chat is closed without keepSocketActive, no network, or the connection has not been established yet | See solutions below |
.messageIsEmpty | The message text is empty | An empty string was passed in .text("") | Validate the text before sending |
.messageTooLong | The text exceeds 4000 characters | The message is too long | Trim the message to 4000 characters |
.messageImageTooLarge | The JPEG size exceeds the server limit (30 MB by default) | The limit is configured server-side | Reduce the image resolution before sending |
.messageImageCompressionError | Image compression failed | Invalid or corrupted UIImage | Validate the UIImage object |
send(message:) does not throw .chatNotOpened or .messageNotSent — no handling is needed.
Handling example
do {
try chatCenterSDK.send(message: .text("Hello"))
} catch ChatCenterUISendMessageError.webSocketNotActive {
// WebSocket is not active — store the message for later sending
pendingMessages.append(message)
} catch ChatCenterUISendMessageError.messageTooLong {
// Trim and retry
let trimmed = String(text.prefix(4000))
try? chatCenterSDK.send(message: .text(trimmed))
} catch {
// Other validation errors
print("Send error: \(error)")
}
Network delivery errors are not delivered as ChatCenterUISendMessageError — send(message:) only checks preconditions (authorization, WebSocket state, content validity).
For REST-layer errors (including file uploads), use ChatCenterUISDKDelegate.chatCenterUI(chatCenter:didReceiveNetwork:) — see SDK Delegate.
WebSocket drops and errors are not delivered through this delegate callback. Track the WebSocket status via send(message:) — it throws .webSocketNotActive when the channel is inactive. To keep the channel active outside the chat screen, enable keepSocketActive (Chat configuration).
Relation between .webSocketNotActive and keepSocketActive
By default, the WebSocket connection is active only while the chat screen is open. Sending via send(message:) without an open chat will fail with .webSocketNotActive.
Solutions
| Approach | Setting | When to use |
|---|---|---|
| Persistent connection | chatConfig.keepSocketActive = true | Background sending, unread counter |
| Connection during a session | chatConfig.keepSocketActiveDuringOperatorSession = true | Notifications during an active dialog |
| Send only inside the chat | No additional settings | When background sending is not needed |
In future SDK versions, keepSocketActive and keepSocketActiveDuringOperatorSession will be replaced by a server-side channelConfig (requested from edna technical support). For new code, prefer the server-side path.
Local values only take effect when chatConfig.shouldUseRemoteConfig = false. With the default (true), the server-side config overrides them. See SDK configuration for details.
Diagnosing errors
Enable logging when initializing the SDK:
let loggerConfig = ChatLoggerConfig(logLevel: .all)
let chatCenterSDK = ChatCenterUISDK(providerUid: "...",
chatConfig: chatConfig,
loggerConfig: loggerConfig)
See Logger configuration for details.
Related sections
- SDK configuration — the
keepSocketActiveparameter and others - Logger configuration — enabling logs for debugging
- Report a bug — how to prepare a report for support
- Messages and unread counter — programmatic sending and receiving of messages