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
4 changes: 2 additions & 2 deletions Sources/AblyChat/ChatAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal final class ChatAPI: Sendable {
// (CHA-M3a) When a message is sent successfully, the caller shall receive a struct representing the Message in response (as if it were received via Realtime event).
internal func sendMessage(roomName: String, params: SendMessageParams) async throws(InternalError) -> Message {
guard let clientId = realtime.clientId else {
throw ARTErrorInfo.create(withCode: 40000, message: "Ensure your Realtime instance is initialized with a clientId.").toInternalError()
throw ARTErrorInfo(chatError: .clientIdRequired).toInternalError()
}

let endpoint = "\(apiVersionV3)/rooms/\(roomName)/messages"
Expand Down Expand Up @@ -106,7 +106,7 @@ internal final class ChatAPI: Sendable {
// (CHA-M8a) A client may update a message via the Chat REST API by calling the update method.
internal func updateMessage(roomName: String, with modifiedMessage: Message, description: String?, metadata: OperationMetadata?) async throws(InternalError) -> Message {
guard let clientID = realtime.clientId else {
throw ARTErrorInfo.create(withCode: 40000, message: "Ensure your Realtime instance is initialized with a clientId.").toInternalError()
throw ARTErrorInfo(chatError: .clientIdRequired).toInternalError()
}

let endpoint = "\(apiVersionV3)/rooms/\(roomName)/messages/\(modifiedMessage.serial)"
Expand Down
14 changes: 12 additions & 2 deletions Sources/AblyChat/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum ErrorCode: Int {
case cannotApplyEventForDifferentMessage
case messageRejectedByBeforePublishRule
case messageRejectedByModeration
case clientIdRequired

internal var toNumericErrorCode: ErrorCode {
switch self {
Expand All @@ -86,6 +87,8 @@ public enum ErrorCode: Int {
.messageRejectedByModeration
case .messageRejectedByBeforePublishRule:
.messageRejectedByBeforePublishRule
case .clientIdRequired:
.badRequest
}
}

Expand All @@ -99,7 +102,8 @@ public enum ErrorCode: Int {
.roomIsReleased,
.roomReleasedBeforeOperationCompleted,
.unableDeleteReactionWithoutName,
.cannotApplyEventForDifferentMessage:
.cannotApplyEventForDifferentMessage,
.clientIdRequired:
400
case .messageRejectedByModeration,
.messageRejectedByBeforePublishRule:
Expand Down Expand Up @@ -170,6 +174,7 @@ internal enum ChatError {
case cannotApplyEventForDifferentMessage
case messageRejectedByBeforePublishRule
case messageRejectedByModeration
case clientIdRequired

internal var codeAndStatusCode: ErrorCodeAndStatusCode {
switch self {
Expand Down Expand Up @@ -202,6 +207,8 @@ internal enum ChatError {
.fixedStatusCode(.messageRejectedByBeforePublishRule)
case .messageRejectedByModeration:
.fixedStatusCode(.messageRejectedByModeration)
case .clientIdRequired:
.fixedStatusCode(.clientIdRequired)
}
}

Expand Down Expand Up @@ -256,6 +263,8 @@ internal enum ChatError {
"The message was rejected before publishing by a rule on the chat room."
case .messageRejectedByModeration:
"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."
}
}

Expand All @@ -276,7 +285,8 @@ internal enum ChatError {
.cannotApplyEventForDifferentMessage,
.unableDeleteReactionWithoutName,
.messageRejectedByBeforePublishRule,
.messageRejectedByModeration:
.messageRejectedByModeration,
.clientIdRequired:
nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ internal class DefaultRoom: InternalRoom {
self.chatAPI = chatAPI

guard let clientId = realtime.clientId else {
throw ARTErrorInfo.create(withCode: 40000, message: "Ensure your Realtime instance is initialized with a clientId.").toInternalError()
throw ARTErrorInfo(chatError: .clientIdRequired).toInternalError()
}

internalChannel = Self.createChannel(roomName: name, roomOptions: options, realtime: realtime)
Expand Down