Skip to content

Commit 98b3c5b

Browse files
committed
fix error handling
1 parent 3d79edf commit 98b3c5b

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Source/Client.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class Client {
9292
writeQueryHostnames = hostnames
9393
} else {
9494
readQueryHostnames = [
95-
"\(appID)-DSN.algolia.net",
95+
"\(appID)-dsn.algolia.net",
9696
"\(appID)-1.algolianet.com",
9797
"\(appID)-2.algolianet.com",
9898
"\(appID)-3.algolianet.com"
@@ -363,16 +363,9 @@ public class Client {
363363
switch(statusCode) {
364364
case 200..<300:
365365
block(JSON: (data as! [String: AnyObject]), error: nil)
366-
case 400:
367-
let errorMessage = data!["message"] as! String
368-
block(JSON: nil, error: NSError(domain: "Bad request argument: \(errorMessage)", code: 400, userInfo: nil))
369-
case 403:
370-
block(JSON: nil, error: NSError(domain: "Invalid Application-ID or API-Key", code: 403, userInfo: nil))
371-
case 404:
372-
block(JSON: nil, error: NSError(domain: "Resource does not exist", code: 404, userInfo: nil))
373366
default:
374-
if let errorMessage = (data as! [String: String])["message"] {
375-
block(JSON: nil, error: NSError(domain: errorMessage, code: 0, userInfo: nil))
367+
if let errorMessage = (data as! [String: AnyObject])["message"] as? String {
368+
block(JSON: nil, error: NSError(domain: errorMessage, code: statusCode, userInfo: nil))
376369
} else {
377370
block(JSON: nil, error: NSError(domain: "No error message", code: 0, userInfo: nil))
378371
}

0 commit comments

Comments
 (0)