Skip to content

sdk: raise NovemException on API errors instead of a print placeholder#236

Draft
bjornars wants to merge 1 commit into
novem-code:mainfrom
bjornars:bsn/sdk-raise-on-api-error
Draft

sdk: raise NovemException on API errors instead of a print placeholder#236
bjornars wants to merge 1 commit into
novem-code:mainfrom
bjornars:bsn/sdk-raise-on-api-error

Conversation

@bjornars

Copy link
Copy Markdown
Contributor

Draft — implements the fail-hard option from #235 for discussion.

What

Adds raise_on_response(r) (api_ref) — parses the server message and any rejected lines and raises the matching NovemException subclass (401/403/404/409, generic NovemException otherwise) — and replaces the print("should raise a general error") placeholder in all eight write sites (vis/group/job/repo, the create_* PUT + api_write POST). Keeps the intentional 409-on-create no-op carve-out.

Why draft

This is the fail-hard direction from #235 — a behavioral change: writes that previously silently no-op'd on a non-2xx now raise. The open questions there should be settled before this goes ready:

  • raise on any non-ok vs 4xx-only (keep 5xx softer/retryable)
  • opt-in raise_on_error/strict flag vs hard default (existing users)
  • does it warrant a major version bump

Verified

Against a live dev API, mail.bcc = [30 addrs over the 25 cap] now raises instead of silently storing nothing:

NovemException: No recipients were changed, the request contained entries that
could not be applied [[email protected]: …maximum of 25 external address
recipients … exceeds it.; …]

The server-side 400 that makes this observable is novem-code/gaia#2810.

Before ready

Refs #235 · SDK half of novem-code/gaia#2656

Every resource write path (vis/group/job/repo `create_*` PUT and
`api_write` POST) handled 404/403/409 but, on any other non-ok response,
printed the body + headers + the literal "should raise a general error"
and returned — so the caller got no exception and silently no-op'd.

Terje hit exactly this (novem-code/gaia#2656): `mail.bcc = [over-cap list]`
returned without error while nothing was stored. The server now rejects
over-cap / unresolvable writes with a 400 + `{message, rejected:[…]}`, but
the SDK swallowed it.

Add `raise_on_response(r)` (api_ref) — parses the server `message` and any
`rejected` lines and raises the matching NovemException subclass (401/403/
404/409 → generic NovemException otherwise) — and call it from all eight
write sites. `mail.bcc = …` over the cap now raises NovemException with the
cap reason and the rejected addresses.
@bjornars

Copy link
Copy Markdown
Contributor Author

@sondove I know there are concerns here. Maybe find a way to opt in to hard-failures, vs the default way of just on error goto next.

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.

1 participant