Skip to content
Understudy Get started

All examples

UnderstudyHTTPNetwork

A server error reaches the client as its own error

Script a status code on a route and check the error the app's own client turns it into, with no network.

Run it

swift test --filter mapsAServerErrorToAppError
The whole file on GitHub
RefreshTokenTests.swift
@Test("A server error reaches the client as its own error")
func mapsAServerErrorToAppError() async {
    server.route(.get, "/me").willReturn(.status(503))

    await #expect(throws: APIError.serviceUnavailable) {
        try await apiClient.currentUser()
    }
    server.route(.get, "/me").willReturn(.status(418))
    await #expect(throws: APIError.unexpectedStatus(418)) {
        try await apiClient.currentUser()
    }
}