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
17 changes: 4 additions & 13 deletions Sources/AblyChat/DefaultMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,13 @@ internal final class DefaultMessages: Messages {
continuation.resume(returning: .success(subscriptionPoint))
} else {
logger.log(message: "Channel is attached, but attachSerial is not defined", level: .error)
continuation.resume(returning: .failure(ARTErrorInfo.create(withCode: 40000, status: 400, message: "Channel is attached, but attachSerial is not defined").toInternalError()))
continuation.resume(returning: .failure(ARTErrorInfo(chatError: .attachSerialIsNotDefined).toInternalError()))
}
case .failed, .suspended:
// TODO: Revisit as part of https://github.com/ably-labs/ably-chat-swift/issues/32
logger.log(message: "Channel failed to attach", level: .error)
let errorCodeCase = ErrorCode.CaseThatImpliesFixedStatusCode.badRequest
continuation.resume(
returning: .failure(
ARTErrorInfo.create(
withCode: errorCodeCase.toNumericErrorCode.rawValue,
status: errorCodeCase.statusCode,
message: "Channel failed to attach"
)
.toInternalError()
)
)
let error = ARTErrorInfo(chatError: .channelFailedToAttach(cause: stateChange.reason)).toInternalError()
logger.log(message: "\(error)", level: .error)
continuation.resume(returning: .failure(error))
default:
break
}
Expand Down
15 changes: 14 additions & 1 deletion Sources/AblyChat/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ internal enum ChatError {
case messageRejectedByBeforePublishRule
case messageRejectedByModeration
case clientIdRequired
case attachSerialIsNotDefined
case channelFailedToAttach(cause: ARTErrorInfo?)

internal var codeAndStatusCode: ErrorCodeAndStatusCode {
switch self {
Expand Down Expand Up @@ -209,6 +211,10 @@ internal enum ChatError {
.fixedStatusCode(.messageRejectedByModeration)
case .clientIdRequired:
.fixedStatusCode(.clientIdRequired)
case .attachSerialIsNotDefined:
.fixedStatusCode(.badRequest)
case .channelFailedToAttach:
.fixedStatusCode(.badRequest)
}
}

Expand Down Expand Up @@ -265,6 +271,10 @@ internal enum ChatError {
"The message was rejected before publishing by a moderation rule on the chat room."
case .clientIdRequired:
"Ensure your Realtime instance is initialized with a clientId."
case .attachSerialIsNotDefined:
"Channel is attached, but attachSerial is not defined."
case let .channelFailedToAttach(cause):
"Channel failed to attach: \(String(describing: cause))"
}
}

Expand All @@ -275,6 +285,8 @@ internal enum ChatError {
cause
case let .roomDiscontinuity(cause):
cause
case let .channelFailedToAttach(cause):
cause
case .nonErrorInfoInternalError,
.inconsistentRoomOptions,
.roomInFailedState,
Expand All @@ -286,7 +298,8 @@ internal enum ChatError {
.unableDeleteReactionWithoutName,
.messageRejectedByBeforePublishRule,
.messageRejectedByModeration,
.clientIdRequired:
.clientIdRequired,
.attachSerialIsNotDefined:
nil
}
}
Expand Down