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

Docs update #33

Merged
merged 1 commit into from
Nov 23, 2023
Merged
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
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,10 @@ If you don't need to decode something from the response and just want to confirm
func logout() async throws
```

Note that if the function return type is Codable or empty, any error that occurs during the request flight, such as an unsuccessful response code, will be thrown.

### Accessing the Raw Response

To just get the raw response you may set the return type to `Response`.

Note that in this case, errors that occur during the flight of the request will NOT be thrown so you should check the `Response.error` property before assuming it was successful.

```swift
@GET("/user")
func getUser() async throws -> Response
Expand All @@ -360,6 +356,22 @@ let (user, res) = try await users.getUser()
print("The response status code was: \(res.statusCode!)")
```

### Error handling

If any error occurs during the request flight, such as an unsuccessful response code, `PapyrusError` will be thrown. You can use it to access failed request and response (if present).
```swift
@GET("/user")
func getUser() async throws -> User

do {
let user = try await users.getUser()
} catch {
if let error = error as? PapyrusError {
print("Error making request \(error.request). Response was: \(error.response)")
}
}
```

## Configuration

### Custom Keys
Expand Down