Skip to content

Expose SAIC’s return code and message on exceptions #54

Closed

Description

@townsmcp

When a call fails, SaicApiException only keeps the combined text, "return code: 8, message: Vehicle not locked.". To act on the reason, callers have to parse that string back apart.

Why it matters: the same code can mean different things, and the message is the only way to tell them apart:

  • Code 8 is used both for "vehicle not locked" and for the remote command limit ("start the vehicle with the key"). They need different handling: one asks the user to lock the car, the other to drive it.
  • Code 4 means the car couldn't be reached, e.g. asleep. Integrations want to treat that as "unreachable" rather than as a failure.
  • 401 / 403 mean the session has expired.

In mg-saic-ha we were parsing str(e) to tell these apart, which breaks if the wording ever changes.

Suggested change:

  • keep return_code and SAIC's message (saic_message) as separate attributes on SaicApiException;
  • add a SaicReturnCode enum for the codes with a known meaning (0, 4, 6, 8, 401, 403, and the library's own 500 for unexpected failures);
  • add simple checks: is_vehicle_unreachable, is_request_rejected, is_vehicle_not_locked, is_logged_out, is_unexpected_failure;
  • keep str(e) exactly as it is, so existing code isn't affected.

Part of #26. I'll open a PR for it.

Activity

  1. nanomad commented on Oct 25, 2026

    @nanomad
    Contributor

    Fixed with #55

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions