Skip to content

Propagate error info to caller#1174

Draft
jlorper wants to merge 5 commits into
rc-v0.6.3from
s224-more-error-info
Draft

Propagate error info to caller#1174
jlorper wants to merge 5 commits into
rc-v0.6.3from
s224-more-error-info

Conversation

@jlorper
Copy link
Copy Markdown
Member

@jlorper jlorper commented Apr 27, 2026

Try to propagate some info to the caller on the FAILED_TO_BUILD_URL error case.

Change implications

  • dependencies added/changed? no
  • something important to note in future release notes?
    • NOTE in CHANGELOG.md anything that will show up in terraform plan/apply that isn't
      obviously a no-op? no
    • breaking changes? if in module/example that is NOT marked alpha, requires major version
      change -> no

RequestUrls requestUrls;
try {
requestUrls = buildRequestedUrls(requestToProxy);
} catch (Throwable e) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this catching Throwable doesn't give us much info on what could be happening.
Provide InvalidTokenException with some error codes (probably we should do something like this so we can have more info on our end on what can be happening in order to help the customer)

// InvalidTokenException extends RuntimeException
if (e instanceof ReversibleTokenizationStrategy.InvalidTokenException ite) {
return HttpEventResponse.builder()
// should this be a 500? Maybe 422 Unprocessable Content?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

500 will make us retry, and same call would yield same results.
I think 422 makes more sense in this case and we can handle globally on Worklytics' side

super(message, cause);

@Getter
public enum ErrorCode {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

maybe not the best approach, but for certain cases (rules exceptions, this, and access errors) could be helpful to exactly know what's going on rather than a generic error

@jlorper jlorper requested review from Copilot and eschultink April 27, 2026 16:41
@jlorper jlorper self-assigned this Apr 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds structured error details to reversible-token decryption failures so callers can distinguish specific FAILED_TO_BUILD_URL / token reversal failure modes.

Changes:

  • Introduces InvalidTokenException.ErrorCode on ReversibleTokenizationStrategy.InvalidTokenException and updates AES token reversal to throw typed error codes.
  • Updates ApiDataRequestHandler to surface token reversal error information to callers when request URL building fails.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
java/gateway-core/src/main/java/com/avaulta/gateway/tokens/impl/AESReversibleTokenizationStrategy.java Switches decryption exception handling to throw InvalidTokenException with structured ErrorCode values.
java/gateway-core/src/main/java/com/avaulta/gateway/tokens/ReversibleTokenizationStrategy.java Adds ErrorCode enum + stores it on InvalidTokenException so callers can inspect a stable identifier.
java/core/src/main/java/co/worklytics/psoxy/gateway/impl/ApiDataRequestHandler.java Returns additional error detail when URL building fails due to token reversal errors, and attempts to propagate the error code in responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +239 to +242
// should this be a 500? Maybe 422 Unprocessable Content?
.statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
.header(ProcessedDataMetadataFields.ERROR.getHttpHeader(),
ErrorCauses.FAILED_TO_BUILD_URL.name())
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

This InvalidTokenException branch returns a 500 with FAILED_TO_BUILD_URL, but the same exception type is handled later as a client/token issue (TOKENIZED_REQUEST_PARAMETER_INVALID with a 409). That inconsistency will make it harder for callers to correctly react to token problems; consider mapping this branch to the same status + error cause as the later catch (or otherwise keep the semantics consistent across both paths).

Suggested change
// should this be a 500? Maybe 422 Unprocessable Content?
.statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
.header(ProcessedDataMetadataFields.ERROR.getHttpHeader(),
ErrorCauses.FAILED_TO_BUILD_URL.name())
.statusCode(HttpStatus.SC_CONFLICT)
.header(ProcessedDataMetadataFields.ERROR.getHttpHeader(),
ErrorCauses.TOKENIZED_REQUEST_PARAMETER_INVALID.name())

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, I agree not a 500 ... whatever 4xx seems most semantically correct for the case.

Comment on lines +236 to +245
// InvalidTokenException extends RuntimeException
if (e instanceof ReversibleTokenizationStrategy.InvalidTokenException ite) {
return HttpEventResponse.builder()
// should this be a 500? Maybe 422 Unprocessable Content?
.statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
.header(ProcessedDataMetadataFields.ERROR.getHttpHeader(),
ErrorCauses.FAILED_TO_BUILD_URL.name())
.body("Error parsing request URL. Error " + ite.getErrorCode().getCode())
.build();
}
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

The newly added behavior that surfaces InvalidTokenException details during URL building (and the associated status/header/body mapping) doesn’t appear to be covered by tests. Please add/extend ApiDataRequestHandlerTest to assert the response status and X-Psoxy-Error header (and any new detail header/body) for this failure mode, so future refactors don’t silently change the contract.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@eschultink eschultink left a comment

Choose a reason for hiding this comment

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

i think just use X-Psoxy-Error that exists; no need to create something else that basically duplicates that.

and return whole error enum name or exception name. No need to add extra levels of indirection to save a few chars, but require us to grep the code to determine the actual error

/**
* a specific error code while processing the request, complements ERROR (optional)
*/
ERROR_CODE("Error-Code"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think Error is a value from an enum ... so is specific

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so if Error is a strict code -- I think eliminate this, just use Error; but if it's freeform message text, OK.


@Getter
public enum ErrorCode {
ALGORITHM_PARAMETER_ERROR("ITE01", "Failed to decrypt token; some algorithm parameter, such as iv, is wrong"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need to be so clever here; just return whole enum names ... don't care about a few extra chars in error case

Base automatically changed from rc-v0.6.0 to main May 8, 2026 16:00
An error occurred while trying to automatically change base from rc-v0.6.0 to main May 8, 2026 16:00
@eschultink eschultink changed the base branch from main to rc-v0.6.1 May 8, 2026 19:14
eschultink and others added 3 commits May 24, 2026 15:24
…ersibleTokenizationStrategy.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use X-Psoxy-Error with full InvalidTokenException.ErrorCode enum names,
return 422 for invalid token failures, and remove the redundant Error-Code header.

Co-authored-by: Cursor <cursoragent@cursor.com>
Base automatically changed from rc-v0.6.1 to main May 27, 2026 10:15
@eschultink eschultink changed the base branch from main to rc-v0.6.2 May 27, 2026 15:28
Base automatically changed from rc-v0.6.2 to main May 29, 2026 21:22
@eschultink eschultink changed the base branch from main to rc-v0.6.3 May 29, 2026 22:04
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.

3 participants