714: Show error is we fail to reset defences - #927
Conversation
chriswilty
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)?
Description
Screenshots
Notes
Concerns
Checklist
Have you done the following?