Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: regenerate sdk #29

Merged
merged 2 commits into from
Mar 7, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "7.0.0"),
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "8.0.0"),
],
```

Expand Down
14 changes: 11 additions & 3 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "7.0.0",
"x-sdk-version": "8.0.0",
"x-appwrite-response-format": "1.6.0"
]

Expand Down Expand Up @@ -337,20 +337,24 @@ open class Client {
var message = ""
var data = try await response.body.collect(upTo: Int.max)
var type = ""
var responseString = ""

do {
let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any]

message = dict?["message"] as? String ?? response.status.reasonPhrase
type = dict?["type"] as? String ?? ""
responseString = String(decoding: data.readableBytesView, as: UTF8.self)
} catch {
message = data.readString(length: data.readableBytes)!
responseString = message
}

throw AppwriteError(
message: message,
code: Int(response.status.code),
type: type
type: type,
response: responseString
)
}

Expand Down Expand Up @@ -434,20 +438,24 @@ open class Client {
default:
var message = ""
var type = ""
var responseString = ""

do {
let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any]

message = dict?["message"] as? String ?? response.status.reasonPhrase
type = dict?["type"] as? String ?? ""
responseString = String(decoding: data.readableBytesView, as: UTF8.self)
} catch {
message = data.readString(length: data.readableBytes)!
responseString = message
}

throw AppwriteError(
message: message,
code: Int(response.status.code),
type: type
type: type,
response: responseString
)
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Appwrite/Models/AppwriteError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ open class AppwriteError : Swift.Error, Decodable {
public let message: String
public let code: Int?
public let type: String?
public let response: String

init(message: String, code: Int? = nil, type: String? = nil) {
init(message: String, code: Int? = nil, type: String? = nil, response: String = "") {
self.message = message
self.code = code
self.type = type
self.response = response
}
}

Expand Down
Loading