Skip to content

kvin API: add explicit success/error envelopes#49

Merged
kenwenzel merged 2 commits intomainfrom
additional-api-response-codes
Apr 14, 2026
Merged

kvin API: add explicit success/error envelopes#49
kenwenzel merged 2 commits intomainfrom
additional-api-response-codes

Conversation

@wmehling
Copy link
Copy Markdown
Contributor

Summary

This PR improves KVIN API explicitness for clients by returning structured success/error envelopes and by making non-404 HTTP failures in KvinHttp explicit instead of silently empty.

Why

  1. Clients previously had ambiguous success/failure handling in KVIN API responses.
  2. Debugging was harder because some failures were generic or implicit.
  3. Explicit status/code/message improves determinism for client logic and supportability.

What Changed

  1. POST /linkedfactory/values: explicit success JSON envelope.
  2. DELETE /linkedfactory/values: explicit success envelope while keeping deleted for compatibility.
  3. Structured JSON errors for key KVIN failure paths (for example INVALID_PAYLOAD, LIMIT_TOO_LARGE, UNSUPPORTED_RESPONSE_TYPE).
  4. KvinHttp: keep 404-as-empty behavior, but non-404 responses now throw explicit runtime errors with status/body context.
  5. Added content-type compatibility guard test to ensure envelope responses are consistently JSON.

Old vs New Behavior (with Test Evidence)

1) POST /linkedfactory/values

  • Old: 200 with empty body.
  • New: 200 with success envelope including success, status, code, message.
  • Tested by: KvinServiceTest#postAndGetRequest

2) DELETE /linkedfactory/values

  • Old: 200 with { "deleted": N }.
  • New: 200 with success envelope plus deleted.
  • Tested by: KvinServiceTest#deleteValuesReturnsExplicitSuccessEnvelope

3) Invalid POST payload

  • Old: generic or unstructured 400.
  • New: structured 400 with code=INVALID_PAYLOAD.
  • Tested by: KvinServiceTest#postRequestInvalidData

4) Limit overflow on GET values

  • Old: generic 400.
  • New: structured 400 with code=LIMIT_TOO_LARGE.
  • Tested by: KvinServiceTest#queryDataWithTooLargeLimitReturnsExplicitError

5) Unsupported response type

  • Old: generic 400.
  • New: structured 400 with code=UNSUPPORTED_RESPONSE_TYPE.
  • Tested by: KvinServiceTest#queryDataWithUnsupportedResponseTypeReturnsExplicitError

6) KvinHttp non-200 behavior

  • Old: non-200 often collapsed to empty iterator behavior.
  • New: 404 still empty; non-404 throws explicit error.
  • Tested by:
  • KvinHttpTest#shouldThrowOnNon404FetchError
  • KvinHttpTest#shouldReturnEmptyOn404Properties

7) Envelope content type stability

  • Old: not guaranteed by tests.
  • New: explicitly guarded as JSON for success and error envelope responses.
  • Tested by: KvinServiceTest#explicitEnvelopeResponsesUseJsonContentType

Backward compatibility

This behavior is now different in client-visible ways (POST body no longer empty, structured JSON errors, and non-404 in KvinHttp now throws instead of silently empty).

@kenwenzel Is that a change that would break code that uses lf-pod or is this explicit behavior acceptable as the new default?

@wmehling wmehling requested a review from kenwenzel April 13, 2026 15:40
@wmehling wmehling self-assigned this Apr 13, 2026
@wmehling wmehling added the enhancement New feature or request label Apr 13, 2026
@kenwenzel
Copy link
Copy Markdown
Member

Thank you for the PR. It is good to have structured JSON responses for errors :-)

I would argue that always returning an envelope is unnecessary as HTTP already has return codes.
For normal insertions I would propose to not send any body in return for successful operations as the HTTP code should be sufficient. This is also the same behavior as, for example, PostgREST is using:
https://docs.postgrest.org/en/v14/references/api/tables_views.html

Furthermore, I would propose to use plain JSON objects for error responses instead of wrapping them within an envelope:
https://docs.postgrest.org/en/v14/references/errors.html

I understand that it is maybe easier to extract response codes from the JSON data but nonetheless the HTTP code needs to be checked first to decide if an error has been occurred or not.

Copy link
Copy Markdown
Member

@kenwenzel kenwenzel left a comment

Choose a reason for hiding this comment

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

Thank you for proposing the changes. I have some minor remarks.

@wmehling
Copy link
Copy Markdown
Contributor Author

Thanks for the review @kenwenzel ! I added the changes requested and also removed the additional JSON fields from the DELETE response (so now it matches the old behavior and the requested adaptations for the POST).

Updates after Review:

  • POST /values success now returns status-only OkResponse (no body)
  • DELETE /values returns deleted-count payload without extra success envelope fields
  • Error JSON payloads use plain object fields: code, message, optional details
  • KvinHttp non-404 failures now throw UncheckedIOException with status/body context
  • Updated KvinServiceTest and KvinHttpTest to match revised contracts

@kenwenzel
Copy link
Copy Markdown
Member

@wmehling Thank you for the update. Maybe we should communicating the deletion count completely?!
Some backends may not be able to report this correctly. This could be the case if whole parquet files are deleted for a specific time range.

@wmehling wmehling requested a review from kenwenzel April 14, 2026 09:39
@kenwenzel kenwenzel merged commit fb32d79 into main Apr 14, 2026
1 check passed
@wmehling wmehling deleted the additional-api-response-codes branch April 14, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants