Skip to content

Conversation

fmenezes
Copy link
Collaborator

@fmenezes fmenezes commented Apr 10, 2025

fixes #33

@fmenezes fmenezes marked this pull request as ready for review April 10, 2025 13:30
Copy link
Collaborator

@gagik gagik left a comment

Choose a reason for hiding this comment

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

Looks good to me, non-blocking question. I think I'll try to introduce some more linting rules for more consistency with i.e. strings and arrow functions later.

private errorMiddleware = (): Middleware => ({
async onResponse({ response }) {
if (!response.ok) {
throw new ApiClientError(`Error calling Atlas API: ${await response.text()}`, response);
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we guaranteed the response text? is there a chance this could error as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed

@fmenezes fmenezes requested a review from gagik April 10, 2025 14:17
if (!response.ok) {
try {
const text = await response.text();
throw new ApiClientError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does mean that what we'll get is
Error calling Atlas API: Error calling Atlas API:...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More like Error calling Atlas API: [400 Bad Request] Invalid json or some other text from backend

Copy link
Collaborator

@gagik gagik Apr 10, 2025

Choose a reason for hiding this comment

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

I think passing the response object is sufficient, we can just omit the response text

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? response is a property and does not display error message directly. You prefer to hide error message?

Copy link
Collaborator

@gagik gagik Apr 10, 2025

Choose a reason for hiding this comment

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

I'd say so. If we want to include properties of the response inside the message (including in format [${response.status} ${response.statusText}]) then let's do it inside the ApiClientError class's super call to message so it's standardized and enforced. And in that sense avoid anything async.

@fmenezes fmenezes merged commit c8f9257 into main Apr 10, 2025
1 check passed
@fmenezes fmenezes deleted the fmenezes/use_openapi_fetch branch April 10, 2025 15:37
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.

[Atlas] Investigate openapi-fetch
2 participants