Skip to content

Adopt error API to convey server errors to the client#151

Open
Hardikrepo wants to merge 1 commit into
apple:mainfrom
Hardikrepo:issue-102-error-api
Open

Adopt error API to convey server errors to the client#151
Hardikrepo wants to merge 1 commit into
apple:mainfrom
Hardikrepo:issue-102-error-api

Conversation

@Hardikrepo

Copy link
Copy Markdown

Summary

  • Adds a PIRServiceError type that serializes the new Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Error protobuf message (from Adding Error API swift-homomorphic-encryption-protobuf#21) as the HTTP response body, following the same HTTPResponseError pattern already used for HeError/PirError.
  • Rewires the four error paths in PIRServiceController.queries() to throw PIRServiceError instead of plain HTTPError:
    • Unknown usecase / unparseable request -> invalidRequest
    • Missing evaluation key -> evaluationKeyNotFound
    • Stale/unknown config id -> configVersionNotFound, now with a fresh ConfigResponse embedded in the error body, so the client can retry immediately without a second config round trip (this is what Document database reloading functionality #94's linked comment asked for).
  • Factored the config-building logic in config() into a shared configResponse(usecases:existingConfigIds:context:) helper reused by both endpoints.

Fixes #102.

Test plan

  • CI (build + swift test)
  • Manual smoke test: send a queries request with a stale configurationHash and confirm the response body decodes as Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Error with configVersionNotFound.configResponse populated

Wire the new Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Error protobuf
message into PIRServiceController.queries(), replacing plain HTTPError
throws with structured PIRServiceError cases. When a client's config id
is stale, the server now embeds a fresh ConfigResponse in the error body
so the client can retry immediately without a second round trip.

@karulont karulont left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR.

I expect there to be unit tests that cover this change.

@@ -0,0 +1,67 @@
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new file that was authored most likely in 2026, not during 2024 and then later changed in 2025.

Suggested change
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
// Copyright 2026 Apple Inc. and the Swift Homomorphic Encryption project authors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File name should probably be PIRServiceError, because this file contains the definition of it.
And the location of it should not be under Extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adopt error API to convey server errors to the client

2 participants