Skip to content

Commit 1ffd2eb

Browse files
committed
Use named errors for URI parsing
1 parent 1568f9d commit 1ffd2eb

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

RMQClient/RMQErrors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ typedef NS_ENUM(NSInteger, RMQError) {
1212
RMQErrorChannelWaitTimeout,
1313
RMQErrorChannelIncorrectSyncMethod,
1414
RMQErrorChannelQueueNameCollision,
15+
16+
RMQErrorInvalidPath,
17+
RMQErrorInvalidScheme,
1518
};

RMQClient/RMQURI.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ + (instancetype)parse:(NSString *)uri error:(NSError *__autoreleasing _Nullable
1717

1818
if (![self isValidScheme:components.scheme]) {
1919
*error = [NSError errorWithDomain:RMQErrorDomain
20-
code:0
20+
code:RMQErrorInvalidScheme
2121
userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK", nil)}];
2222
return nil;
2323
}
@@ -61,7 +61,7 @@ + (NSString *)parseVhost:(NSURLComponents *)components error:(NSError **)error {
6161

6262
if (numberOfSlashes > 2) {
6363
NSString *msg = [NSString stringWithFormat:@"%@ has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %%2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris", components.URL];
64-
*error = [NSError errorWithDomain:RMQErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(msg, nil)}];
64+
*error = [NSError errorWithDomain:RMQErrorDomain code:RMQErrorInvalidPath userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(msg, nil)}];
6565
return nil;
6666
} else if (components.path.length == 0) {
6767
return @"/";

RMQClientTests/RMQURIParseTest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import XCTest
33
class RMQURIParseTest: XCTestCase {
44

55
func testNonAMQPSchemesNotAllowed() {
6-
XCTAssertThrowsError(try RMQURI.parse("amqpfoo://dev.rabbitmq.com")) { (error) in
6+
XCTAssertThrowsError(try RMQURI.parse("amqpfoo://dev.rabbitmq.com")) { error in
77
do {
88
XCTAssertEqual(
9-
"Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK",
10-
(error as NSError).localizedDescription
9+
RMQError.InvalidScheme.rawValue,
10+
(error as NSError).code
1111
)
1212
}
1313
}
@@ -50,8 +50,8 @@ class RMQURIParseTest: XCTestCase {
5050
XCTAssertThrowsError(try RMQURI.parse("amqp://dev.rabbitmq.com/a/path/with/slashes")) { (error) in
5151
do {
5252
XCTAssertEqual(
53-
"amqp://dev.rabbitmq.com/a/path/with/slashes has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris",
54-
(error as NSError).localizedDescription
53+
RMQError.InvalidPath.rawValue,
54+
(error as NSError).code
5555
)
5656
}
5757
}

0 commit comments

Comments
 (0)