Skip to content

feat: surface UNPROCESSABLE_ENTITY reason when invite fails - #38

Open
Hayena wants to merge 1 commit into
mainfrom
feat/issue-21-invite-unprocessable-entity
Open

feat: surface UNPROCESSABLE_ENTITY reason when invite fails#38
Hayena wants to merge 1 commit into
mainfrom
feat/issue-21-invite-unprocessable-entity

Conversation

@Hayena

@Hayena Hayena commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements #21

OrganizationService.invite() previously returned NotFound for both HTTP 404 and 422, silently losing the reason an invitation failed (e.g. user is already a member, validation error). This PR separates the two cases so callers get meaningful feedback.

Changes

  • GitHubOrganizationClient.invite() now handles UNPROCESSABLE_ENTITY (422) separately from NOT_FOUND (404)
  • 422 → ApiResult.Failure with the error message extracted from the response body
  • 404 → ApiResult.NotFound (unchanged)
  • GitHubApiException.from() updated to extract the message field from JSON response bodies
  • KDoc for invite() updated to document all outcomes
  • Unit tests added for the 422 case

Before / After

// Before — 422 was indistinguishable from 404
when (client.organizations.invite(org, "octocat")) {
    is ApiResult.Found    -> println("Invited")
    is ApiResult.NotFound -> println("Not found or validation failed") // ambiguous
    is ApiResult.Failure  -> println("Error")
}

// After — reason is explicit
when (client.organizations.invite(org, "octocat")) {
    is ApiResult.Found    -> println("Invited")
    is ApiResult.NotFound -> println("Organisation not found")
    is ApiResult.Failure  -> println("Failed: ${result.exception.message}") // e.g. "Validation Failed: already a member"
}

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