Skip to content

Commit

Permalink
Update README.md (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Nov 23, 2023
1 parent bb739bb commit d089682
Showing 1 changed file with 16 additions and 4 deletions.
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

0 comments on commit d089682

Please sign in to comment.