Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing an exception in a custom formatter doesn't set the http status as expected #3295

Open
HassanAzzam opened this issue Oct 2, 2024 · 3 comments

Comments

@HassanAzzam
Copy link

I'm using the tableExport API, and currently trying to conditionally enable a PDF formatter on specific resource types(as it requires prerequisites such as an HTML template .. etc), hence, I throw an exception inside the formatter whenever an unsupported resource type is requested to be exported.

Expected Behavior

To have the exception message in the queueing response alongside the status code(4xx, maybe 422), something like this:

{
  "data": {
    "type": "tableExport",
    "id": "011f99aa-cc41-4c5b-bbb0-d3478aa9d8ac",
    "attributes": {
      ...
      "result": {
		...
        "recordCount": null,
        "httpStatus": 422,
        "url": null,
        "message": "Type [xxx] is not PDF exportable."
      }
    }
  }
}

Current Behavior

I get everything as expected unless for the status code, returning 200.

{
  "data": {
    "type": "tableExport",
    "id": "011f99aa-cc41-4c5b-bbb0-d3478aa9d8ac",
    "attributes": {
      ...
      "result": {
		...
        "recordCount": null,
        "httpStatus": 200,
        "url": null,
        "message": "Type [xxx] is not PDF exportable."
      }
    }
  }
}

Steps to Reproduce

  1. Create a custom formatter for table export api.
  2. Throw an error inside the formatter.
  3. Try to trigger the formatter through table export api.

Context

Trying to inspect the status of the requested export.
Async API
TableExport API

Your Environment

  • Elide version used: 7.1.2
  • Environment name and version (Java 1.8.0_152): openjdk 17.0.9 2023-10-17
  • Operating System and version: MacOS 10.15
  • Spring boot: 3.2.5
@justin-tay
Copy link
Collaborator

This looks like it is currently by design, similar to GraphQL where queries always return HTTP status code 200. If message is set an error has occurred.

// Follows same flow as GraphQL. The query may result in failure but request was successfully processed.
exportResult.setHttpStatus(200);
exportResult.setCompletedOn(new Date());
elide.getTransactionRegistry().removeRunningTransaction(requestId);
elide.getAuditLogger().clear();

@HassanAzzam
Copy link
Author

Any recommendations to get around this? Or at least to differentiate between accepted and rejected requests?

@justin-tay
Copy link
Collaborator

If the request is accepted the message should be null and if it's rejected then message will be present?

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

No branches or pull requests

2 participants