Skip to content

[2.0] Fixes #38023: preserve 424 FAILED_SEND_EMAIL in signup/password-reset flows (backport 2.0 #38051) - #38232

Merged
yan-3005 merged 1 commit into
2.0from
backport/2.0/fixes-38023-preserve-424-failed-send-email
Nov 19, 2026
Merged

yan-3005 merged 1 commit into
2.0from
backport/2.0/fixes-38023-preserve-424-failed-send-email

Conversation

@yan-3005

@yan-3005 yan-3005 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #38051 to 2.0. Issue: #38023.

What

CustomExceptionMessage(int, ...) coerced the status through Response.Status.fromStatusCode(...), which returns null for codes outside the enum (424). The null status made WebServiceException.getResponse() throw IllegalArgumentException inside the exception mapper, so the basic-auth email-failure paths (signup, resend registration token, password reset) answered a generic 500 with an empty body. WebServiceException now keeps the raw int status code, so they answer 424 again.

Differences from the main PR

  • CatalogGenericExceptionMapperTest does not exist on 2.0 (cherry-pick conflict); it is added here with only the two tests from Fixes #38023: preserve 424 FAILED_SEND_EMAIL in signup/password-reset flows #38051.
  • On 2.0 the mapper renders every WebServiceException body as {code, message} — the typed errorType body (ADR 2026-11-14 typed client errors) is a later main/2.1 change and is not backported. So 2.0 returns 424 without errorType: FAILED_SEND_EMAIL; the mapper test asserts the 424 status, code and message accordingly. The 2.0 UI keys this flow on the 424 status (HTTP_STATUS_CODE.FAILED_DEPENDENCY), not on errorType.

Tests

  • Unit (reactor build on this branch): SecurityUtilTest, BasicAuthenticatorEmailFailureTest, CatalogGenericExceptionMapperTest, CustomExceptionMessageTest — Tests run: 66, Failures: 0, Errors: 0. spotless:check clean.
  • RED on this branch (original 2.0 WebServiceException/CustomExceptionMessage, new tests kept): all 6 new tests fail with Response status must not be 'null' (Tests run: 60, Failures: 1, Errors: 5).

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

Satisfy the repository's test and style requirements before merging; no blocking runtime defect was found in the email-status fix.

Findings

  1. P2 Duplicate tests add no coverage ▶
  2. P2 Tests mock internal storage ▶
  3. P2 Repeated strings need constants ▶
  4. P2 Unchanged values lack final ▶

Summary

This backport preserves HTTP 424 when signup or password-reset emails fail, while keeping the 2.0 response body unchanged.

  • Basic-auth email failures reach callers with their intended HTTP status.

Reviews (1) · Last reviewed commit: "Fixes #38023: preserve 424 FAILED_SEND_E..." · Reviewed by Greptile

… flows (#38051)

* fix(auth): preserve raw HTTP status for non-enum codes in WebServiceException

* test(auth): assert persisted password on reset email-failure path

Address greptile feedback on BasicAuthenticatorEmailFailureTest: capture
the User handed to createOrUpdate and verify it carries a BCrypt hash of
the requested new password, so the test fails if the password is never
set on the saved user (instead of relying solely on createOrUpdate
being called).

---------

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
(cherry picked from commit 2cc8c55)
@yan-3005
yan-3005 requested a review from a team as a code owner November 19, 2026 16:14
@yan-3005
yan-3005 requested review from TeddyCr and removed request for a team November 19, 2026 16:14
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Comment on lines 19 to 33
public WebServiceException(Response.Status status, String errorType, String message) {
super(message);
this.status = status;
this.statusCode = status.getStatusCode();
this.errorType = errorType;
this.message = message;
}

public WebServiceException(int status, String errorType, String message) {
super(message);
this.statusCode = status;
this.errorType = errorType;
this.message = message;
}

public WebServiceException(

@gitar-bot gitar-bot Bot Nov 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: Enum ctor now NPEs on null status from fromStatusCode callers

The Response.Status constructors now call status.getStatusCode() as soon as the exception is built (lines 21, 36). Some callers still pass Response.Status.fromStatusCode(response.statusCode()), for example AirflowRESTClient.clientException(...) (line ~913) and IngestionPipelineDeploymentException.byMessage(...) (line ~413). That call returns null for any code missing from the enum, such as 422 or 424 from Airflow. Before this PR the exception was still created and failed later in getResponse(). Now new PipelineServiceClientException(...) throws an NPE inside the client code, so the Airflow error message is lost. The catch (PipelineServiceClientException) handlers in MeteredPipelineServiceClient and IngestionPipelineRepository are also skipped. This is the same non-enum-status bug the PR fixes, still present on the enum path. Fix: make the enum constructors null-safe, or give those callers int overloads that pass response.statusCode() directly.

Fall back to 500 when a null enum status is passed instead of NPE-ing at construction:

public WebServiceException(Response.Status status, String errorType, String message) {
  this(toStatusCode(status), errorType, message);
}

private static int toStatusCode(Response.Status status) {
  return status == null
      ? Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
      : status.getStatusCode();
}

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 🟡 Medium risk 0 closed / 1 findings

Preserving raw status codes changes signup and password-reset email failures from 500 to 424, which may alter client error handling.

Preserves the raw int HTTP status in WebServiceException so basic-auth email-failure paths (signup, resend registration token, password reset) return 424 instead of a generic 500 with an empty body. One open suggestion: the enum-based constructors now throw an NPE when Response.Status.fromStatusCode(...) returns null for codes like 422 or 424, as in AirflowRESTClient.clientException(...) and IngestionPipelineDeploymentException.byMessage(...). Making those constructors null-safe or adding int overloads would avoid losing the Airflow error message.

💡 Edge Case: Enum ctor now NPEs on null status from fromStatusCode callers

📄 openmetadata-spec/src/main/java/org/openmetadata/sdk/exception/WebServiceException.java:19-33

The Response.Status constructors now call status.getStatusCode() as soon as the exception is built (lines 21, 36). Some callers still pass Response.Status.fromStatusCode(response.statusCode()), for example AirflowRESTClient.clientException(...) (line ~913) and IngestionPipelineDeploymentException.byMessage(...) (line ~413). That call returns null for any code missing from the enum, such as 422 or 424 from Airflow. Before this PR the exception was still created and failed later in getResponse(). Now new PipelineServiceClientException(...) throws an NPE inside the client code, so the Airflow error message is lost. The catch (PipelineServiceClientException) handlers in MeteredPipelineServiceClient and IngestionPipelineRepository are also skipped. This is the same non-enum-status bug the PR fixes, still present on the enum path. Fix: make the enum constructors null-safe, or give those callers int overloads that pass response.statusCode() directly.

Fall back to 500 when a null enum status is passed instead of NPE-ing at construction
public WebServiceException(Response.Status status, String errorType, String message) {
  this(toStatusCode(status), errorType, message);
}

private static int toStatusCode(Response.Status status) {
  return status == null
      ? Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
      : status.getStatusCode();
}
🤖 Prompt for agents
Code Review: Preserves the raw int HTTP status in `WebServiceException` so basic-auth email-failure paths (signup, resend registration token, password reset) return 424 instead of a generic 500 with an empty body. One open suggestion: the enum-based constructors now throw an NPE when `Response.Status.fromStatusCode(...)` returns null for codes like 422 or 424, as in `AirflowRESTClient.clientException(...)` and `IngestionPipelineDeploymentException.byMessage(...)`. Making those constructors null-safe or adding int overloads would avoid losing the Airflow error message.

1. 💡 Edge Case: Enum ctor now NPEs on null status from fromStatusCode callers
   Files: openmetadata-spec/src/main/java/org/openmetadata/sdk/exception/WebServiceException.java:19-33

   The `Response.Status` constructors now call `status.getStatusCode()` as soon as the exception is built (lines 21, 36). Some callers still pass `Response.Status.fromStatusCode(response.statusCode())`, for example `AirflowRESTClient.clientException(...)` (line ~913) and `IngestionPipelineDeploymentException.byMessage(...)` (line ~413). That call returns null for any code missing from the enum, such as 422 or 424 from Airflow. Before this PR the exception was still created and failed later in `getResponse()`. Now `new PipelineServiceClientException(...)` throws an NPE inside the client code, so the Airflow error message is lost. The `catch (PipelineServiceClientException)` handlers in `MeteredPipelineServiceClient` and `IngestionPipelineRepository` are also skipped. This is the same non-enum-status bug the PR fixes, still present on the enum path. Fix: make the enum constructors null-safe, or give those callers int overloads that pass `response.statusCode()` directly.

   Fix (Fall back to 500 when a null enum status is passed instead of NPE-ing at construction):
   public WebServiceException(Response.Status status, String errorType, String message) {
     this(toStatusCode(status), errorType, message);
   }
   
   private static int toStatusCode(Response.Status status) {
     return status == null
         ? Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
         : status.getStatusCode();
   }

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Comment on lines +55 to +65
@Test
void basicAuthEmailFailureConstantsRenderAs424() {
Response response =
new CatalogGenericExceptionMapper()
.toResponse(
new CustomExceptionMessage(424, "FAILED_SEND_EMAIL", "Email sending issue"));

assertEquals(424, response.getStatus());
JsonNode body = JsonUtils.valueToTree(response.getEntity());
assertEquals(424, body.path("code").asInt());
assertEquals("Email sending issue", body.path("message").asText());

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.

P2 Duplicate tests add no coverage. Both mapper tests pass the same exception with the same literal values and check the same response. The second test does not use the constants its name promises to check. Keep one test, or make the second exercise a distinct case. The repository guide says copy-pasted logic must be shared rather than duplicated.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +186 to +200
ArgumentCaptor<User> savedUser = ArgumentCaptor.forClass(User.class);
verify(userRepository)
.createOrUpdate(nullable(UriInfo.class), savedUser.capture(), anyString());
User persisted = savedUser.getValue();
assertNotNull(persisted.getAuthenticationMechanism(), "auth mechanism must be set");
BasicAuthMechanism config =
(BasicAuthMechanism) persisted.getAuthenticationMechanism().getConfig();
assertNotNull(config, "basic-auth config must be set on the persisted user");
assertTrue(
BCrypt.verifyer()
.verify("Password123!".toCharArray(), config.getPassword().toCharArray())
.verified,
"the persisted password must be a BCrypt hash of the requested new password");
verify(tokenRepository)
.deleteTokenByUserAndType(user.getId(), TokenType.PASSWORD_RESET.toString());

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.

P2 Tests mock internal storage. The new tests replace UserRepository, TokenRepository, and Entity, then use verify() to claim that passwords and tokens were saved or removed. Inspecting the captured user proves the hash was prepared, not that it was stored. The repository guide says to mock boundaries, not internal classes, and to check database state rather than internal calls. Move these storage checks into integration tests with real repositories; keep the email failure at the boundary.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +594 to +596
assertTrue(
outputStream.content().contains("Email sending issue"),
"the failure message must reach the client");

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.

P2 Repeated strings need constants. The added check passes a raw string to contains(). The same email message and error name are also repeated across the new tests. The repository guide forbids raw strings in contains() and requires named constants for repeated strings. Use the existing email-error constants and shared test values where appropriate.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +26 to 30
public WebServiceException(int status, String errorType, String message) {
super(message);
this.statusCode = status;
this.errorType = errorType;
this.message = message;

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.

P2 Unchanged values lack final. The new constructor parameters and new test locals are never reassigned but omit final. The repository guide requires final on parameters and local variables that do not change. Apply it to the new declarations; the mapper test's response and body are two more examples.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@yan-3005
yan-3005 merged commit 6e57d0b into 2.0 Nov 19, 2026
79 of 88 checks passed
@yan-3005
yan-3005 deleted the backport/2.0/fixes-38023-preserve-424-failed-send-email branch November 19, 2026 17:45
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.

2 participants