Skip to content

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.

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