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

Possibility to communicate warnings together with data result from backend. #822

Open
anders-kiaer opened this issue Dec 5, 2024 · 1 comment

Comments

@anders-kiaer
Copy link
Collaborator

A common use case for this is e.g. that you want to calculate statistics over a given set of realizations, and then when the backend does the calculation, it discovers that for the data type in question + set of realizations, some of them are missing the necessary data.

In some cases, it would be preferred to calculate statistics over the realizations that do have data, and at the same time communicate to the user which realizations where forced to be removed from the calculation.

@rubenthoms
Copy link
Collaborator

rubenthoms commented Dec 20, 2024

There are several parts of this task that require some research and evaluation

Transportation of warnings from backend to frontend via HTTP

On first read, this sounds like a quite nice approach: https://samredai.com/blog/context-aware-fastapi/

Creating responses in FastAPI

We somehow need to add the warning to either the header or the response. Do we change the way we return data from our endpoints to a function taking the actual response data + potential warnings/errors and creates a unified response? What are alternatives?

Consuming the responses frontend

How can we intercept the warnings/errors coming from backend in a HTTP response in an automated manner? We need access to:

  • The response body and potentially the header (depending on the means of transportation)
  • The module instance id
    We want the HTTP response as an input and the actual response data and warning as two separate outputs. The former gets send to the module that made the request, the second one is passed automatically to the module instance.
    Where do we (need to) intercept?
  • Axios - difficult as all functions are auto-generated
  • Tanstack Query - has no access to the header information and is very close to the actual module implementation level
  • An optional wrapper around the @api calls in useQuery calls that do the separation for us - would require the module instance id

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