Skip to content

Commit

Permalink
Add prefix to internal errors
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
  • Loading branch information
piotrpio committed Feb 7, 2024
1 parent 65addc2 commit b3a9e68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Sources/NatsSwift/NatsClient/NatsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ extension Client {
//TODO(jrm): handle response
logger.debug("connect")
guard let connectionHandler = self.connectionHandler else {
throw NatsClientError("empty connection handler")
throw NatsClientError("internal error: empty connection handler")
}
try await connectionHandler.connect()
}

public func close() async throws {
logger.debug("close")
guard let connectionHandler = self.connectionHandler else {
throw NatsClientError("empty connection handler")
throw NatsClientError("internal error: empty connection handler")
}
try await connectionHandler.close()
}
Expand All @@ -77,23 +77,23 @@ extension Client {
) throws {
logger.debug("publish")
guard let connectionHandler = self.connectionHandler else {
throw NatsClientError("empty connection handler")
throw NatsClientError("internal error: empty connection handler")
}
try connectionHandler.write(operation: ClientOp.publish((subject, reply, payload, headers)))
}

public func flush() async throws {
logger.debug("flush")
guard let connectionHandler = self.connectionHandler else {
throw NatsClientError("empty connection handler")
throw NatsClientError("internal error: empty connection handler")
}
connectionHandler.channel?.flush()
}

public func subscribe(to subject: String) async throws -> Subscription {
logger.info("subscribe to subject \(subject)")
guard let connectionHandler = self.connectionHandler else {
throw NatsClientError("empty connection handler")
throw NatsClientError("internal error: empty connection handler")
}
return try await connectionHandler.subscribe(subject)

Expand Down
4 changes: 2 additions & 2 deletions Sources/NatsSwift/NatsConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ConnectionHandler: ChannelInboundHandler {
self.state = .connected
self.fire(.connected)
guard let channel = self.channel else {
throw NatsClientError("empty channel")
throw NatsClientError("internal error: empty channel")
}
// Schedule the task to send a PING periodically
let pingInterval = TimeAmount.nanoseconds(Int64(self.pingInterval * 1_000_000_000))
Expand Down Expand Up @@ -381,7 +381,7 @@ class ConnectionHandler: ChannelInboundHandler {

func write(operation: ClientOp) throws {
guard let allocator = self.channel?.allocator else {
throw NatsClientError("no allocator")
throw NatsClientError("internal error: no allocator")
}
let payload = try operation.asBytes(using: allocator)
try self.writeMessage(payload)
Expand Down

0 comments on commit b3a9e68

Please sign in to comment.