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

714: Show error is we fail to reset defences #927

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

calummcgowan
Copy link

@calummcgowan calummcgowan commented Nov 4, 2024

Description

Screenshots

Screenshot 2024-11-04 110448

Notes

  • Changes made to MainComponent.tsx: add chat message when resetDefence fails
  • Changes to defenceService.ts: return null when DefenceResetResponse promise fails

Concerns

  • No unit tests added - may be irrelevant due to running only frontend

Checklist

Have you done the following?

  • Linked the relevant Issue
  • [] Added tests
  • Ensured the workflow steps are passing

Copy link
Member

@chriswilty chriswilty left a comment

Choose a reason for hiding this comment

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

Sorry it took a while to get around to a review.

This does the job, thank you! I have a small request for a minor enhancement, and another to use async/await instead of a promise chain.

defenceId,
configItemId,
level,
});
return (await response.json()) as DefenceResetResponse;
}).then(
Copy link
Member

@chriswilty chriswilty Jan 20, 2025

Choose a reason for hiding this comment

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

We have a mix of promises and async/awaits here. Prefer async/await wherever possible (and here it is possible).

Note that fetch does not throw an error for non-200 status codes, so this will fail when the service (legitimately) returns text/plain error messages, as the body then is not JSON. I appreciate that a) that was already happening, and b) the acceptance criteria specified only what should happen when the server is unavailable (which does indeed result in an error thrown) but we have the opportunity to make this more robust if we check for response.ok ...

As this project is so infrequently updated, may I ask for a little more from you? Firstly, use async/await and try/catch for consistency, and secondly, could you check for response.ok and if false, then console.warn the response text (and then return null)?

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.

Show error if we fail to reset defences
2 participants