[PR 11] Frontend HttpClient & Either Conversion (E7.S3, E1.S6) #57

Closed
opened 2025-06-24 23:46:32 +00:00 by rwachters · 0 comments
rwachters commented 2025-06-24 23:46:32 +00:00 (Migrated from github.com)

Summary

Implement the concrete KtorHttpClient setup in app/api/client, configured with the port from backend startup and JSON serialization. Add error handling and conversion to Arrow's Either type for all API calls.

Details

  • Set up a KtorHttpClient in the frontend (app/api/client), using the port provided by the embedded Ktor server (from PR 7).
  • Configure JSON serialization for all requests and responses.
  • Create an ApiException class for error handling.
  • Implement a utility function or base class for API calls that wraps Ktor's client.get(...), post(...), etc. in a try/catch block.
  • On HttpResponseException, deserialize the response body into an ApiError and return Either.Left(apiError).
  • On success, return Either.Right(result).
  • Handle other exceptions (network, deserialization) by wrapping them in a generic ApiError (e.g., INTERNAL, EXTERNAL_SERVICE_ERROR) and returning Either.Left.
  • Use Arrow's Either for all API call results, with logical errors only.

Dependencies

  • PR 7 (Ktor server startup and port communication)
  • Ktor client libraries, kotlinx.serialization, Arrow Core

Tests

  • Add unit/integration tests for the API client helper/base logic to ensure it correctly produces Either.Left or Either.Right based on responses (can mock Ktor responses for this).

References

  • See docs/status/PRs v1.2.md, item 11.
  • See Epic E1.S6 and E7.S3 in docs/Epic-Stories/User Stories v1.2.md.

Assignee

Maya

Labels

frontend, api, ktor, arrow, good first issue

## Summary Implement the concrete `KtorHttpClient` setup in `app/api/client`, configured with the port from backend startup and JSON serialization. Add error handling and conversion to Arrow's `Either` type for all API calls. ## Details - Set up a `KtorHttpClient` in the frontend (`app/api/client`), using the port provided by the embedded Ktor server (from PR 7). - Configure JSON serialization for all requests and responses. - Create an `ApiException` class for error handling. - Implement a utility function or base class for API calls that wraps Ktor's `client.get(...)`, `post(...)`, etc. in a `try/catch` block. - On `HttpResponseException`, deserialize the response body into an `ApiError` and return `Either.Left(apiError)`. - On success, return `Either.Right(result)`. - Handle other exceptions (network, deserialization) by wrapping them in a generic `ApiError` (e.g., `INTERNAL`, `EXTERNAL_SERVICE_ERROR`) and returning `Either.Left`. - Use Arrow's `Either` for all API call results, with logical errors only. ## Dependencies - PR 7 (Ktor server startup and port communication) - Ktor client libraries, `kotlinx.serialization`, Arrow Core ## Tests - Add unit/integration tests for the API client helper/base logic to ensure it correctly produces `Either.Left` or `Either.Right` based on responses (can mock Ktor responses for this). ## References - See docs/status/PRs v1.2.md, item 11. - See Epic E1.S6 and E7.S3 in docs/Epic-Stories/User Stories v1.2.md. ## Assignee Maya ## Labels frontend, api, ktor, arrow, good first issue
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Torvian.eu/chatbot#57
No description provided.