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

828 streamline configure defence info message network call #874

Conversation

pmarsh-scottlogic
Copy link
Contributor

@pmarsh-scottlogic pmarsh-scottlogic commented Mar 22, 2024

⚠ Note, don't believe the branch name!

Description

Before, when the user would configure a defence, we would send a request to the backend. If the backend successfully configured the defence, then the frontend would send a further request to add the info message to the chat history, eg 'character limit defence updated'.

This PR changes it so that when the backend successfully configures a defence, the backend generates the info message and appends it to the history, then forwards it on to the frontend.

Concerns

Checklist

Have you done the following?

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

@pmarsh-scottlogic pmarsh-scottlogic marked this pull request as ready for review March 22, 2024 09:19
@pmarsh-scottlogic pmarsh-scottlogic changed the title 828 streamline configure chat model info message network call 828 streamline configure defence info message network call Mar 22, 2024
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.

Looks like your changes have uncovered some unhandled error cases - or at least, swallowed ones. Could be a nice win for our final week!

null | string,
| string
| {
resultingChatInfoMessage: ChatInfoMessage;
Copy link
Member

Choose a reason for hiding this comment

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

string or object - is that cos we have some error responses with a string body?

What do we do with those error responses? I'm now checking your changes in defenceService...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sometimes we return an error message a simple string. Also yes, we swallow those. I suppose they remain helpful because you can see them in the browser inspector.

A note on these request types: This second part (ResBody) seems entirely redundant. TypeScript doesn't seem to enforce the types at all when you call res.send(...). Are we missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Yep I noticed that as well. I couldn't at the time work out what we were doing wrong, but now I look again, I think we should be accessing the response object from the request, i.e. req.res instead of passing a separate, untyped Response object to our handler functions.

return response.status === 200;

const { resultingChatInfoMessage } =
(await response.json()) as ConfigureDefenceResponse;
Copy link
Member

@chriswilty chriswilty Mar 25, 2024

Choose a reason for hiding this comment

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

This could be problematic because the response type in the case of errors is not application/json, it's text/plain. So I expect response.json() to fail in that case. Did you try it?

Better to check the status first, and if Ok then parse the JSON and make your DTO. And if it's not Ok, what happens to the error message? Looks like we are swallowing that currently.

Update Yep we are ignoring defence config errors when we could at least be writing something to the console, or better still, showing an error message somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, good call to check the status first. And yes, the message gets swallowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not-swallowing the errors is a wider UI problem I reckon

Copy link
Member

Choose a reason for hiding this comment

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

It's that "unhappy paths" issue come back to bite us 😁

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.

Beautiful!

@pmarsh-scottlogic pmarsh-scottlogic merged commit 7e0e0b6 into dev Mar 26, 2024
4 checks passed
@pmarsh-scottlogic pmarsh-scottlogic deleted the 828-streamline-configure-chat-model-info-message-network-call branch March 26, 2024 16:56
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.

Stop adding messages to backend history via frontend 🛠🛠
2 participants