Skip to content

Commit 26d20c1

Browse files
committed
Error message improvements
1 parent 3fa72da commit 26d20c1

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,15 @@ You can easily copy or rename an existing index using the `copy` and `move` comm
868868
869869
```swift
870870
// Rename MyIndex in MyIndexNewName
871-
client.moveIndex("MyIndex", dstIndexName: "MyIndexNewName", block: { (JSON, error) -> Void in
871+
client.moveIndex("MyIndex", to: "MyIndexNewName", block: { (JSON, error) -> Void in
872872
if let error = error {
873873
println("Move failure: \(error)")
874874
} else {
875875
println("Move success: \(JSON)")
876876
}
877877
})
878878
// Copy MyIndex in MyIndexCopy
879-
client.copyIndex("MyIndex", dstIndexName: "MyIndexCopy", block: { (JSON, error) -> Void in
879+
client.copyIndex("MyIndex", to: "MyIndexCopy", block: { (JSON, error) -> Void in
880880
if let error = error {
881881
println("Copy failure: \(error)")
882882
} else {

Source/Client.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public class Client {
161161
///
162162
/// :param: srcIndexName the name of index to move.
163163
/// :param: dstIndexName the new index name that will contains sourceIndexName (destination will be overriten if it already exist).
164-
public func moveIndex(srcIndexName: String, dstIndexName: String, block: CompletionHandler? = nil) {
164+
public func moveIndex(srcIndexName: String, to dstIndexName: String, block: CompletionHandler? = nil) {
165165
let path = "1/indexes/\(srcIndexName.urlEncode())/operation"
166166
let request = [
167167
"destination": dstIndexName,
@@ -175,7 +175,7 @@ public class Client {
175175
///
176176
/// :param: srcIndexName the name of index to copy.
177177
/// :param: dstIndexName the new index name that will contains a copy of sourceIndexName (destination will be overriten if it already exist).
178-
public func copyIndex(srcIndexName: String, dstIndexName: String, block: CompletionHandler? = nil) {
178+
public func copyIndex(srcIndexName: String, to dstIndexName: String, block: CompletionHandler? = nil) {
179179
let path = "1/indexes/\(srcIndexName.urlEncode())/operation"
180180
let request = [
181181
"destination": dstIndexName,
@@ -361,7 +361,8 @@ public class Client {
361361
case 200, 201:
362362
block(JSON: (data as [String: AnyObject]), error: nil)
363363
case 400:
364-
block(JSON: nil, error: NSError(domain: "Bad request argument", code: 400, userInfo: nil))
364+
let errorMessage = data!["message"] as String
365+
block(JSON: nil, error: NSError(domain: "Bad request argument: \(errorMessage)", code: 400, userInfo: nil))
365366
case 403:
366367
block(JSON: nil, error: NSError(domain: "Invalid Application-ID or API-Key", code: 403, userInfo: nil))
367368
case 404:

Tests/ClientTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ClientTests: XCTestCase {
115115
} else {
116116
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
117117

118-
self.client.moveIndex(self.index.indexName, dstIndexName: "algol?à-swift2", block: { (JSON, error) -> Void in
118+
self.client.moveIndex(self.index.indexName, to: "algol?à-swift2", block: { (JSON, error) -> Void in
119119
if let error = error {
120120
XCTFail("Error during moveIndex: \(error)")
121121
expecation.fulfill()
@@ -175,7 +175,7 @@ class ClientTests: XCTestCase {
175175
} else {
176176
XCTAssertEqual(JSON!["status"] as String, "published", "Wait task failed")
177177

178-
self.client.copyIndex(self.index.indexName, dstIndexName: "algol?à-swift2", block: { (JSON, error) -> Void in
178+
self.client.copyIndex(self.index.indexName, to: "algol?à-swift2", block: { (JSON, error) -> Void in
179179
if let error = error {
180180
XCTFail("Error during copyIndex: \(error)")
181181
expecation.fulfill()

0 commit comments

Comments
 (0)