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

Fix app crashing when bot code causes an error #64

Merged
merged 6 commits into from
Jul 30, 2024

Conversation

ashleysmithTTD
Copy link
Contributor

@ashleysmithTTD ashleysmithTTD commented Jul 29, 2024

App was crashing when botnet traffic tried to send information to TCPortal

The Fix: adding a try-catch block and logging the error instead of an error thrown inside the Zod code

Test plan:
Must have local operator running
Open Powershell ISE and paste this example script into the file:

$params = @{"@type"="login";
 "username"="[email protected]";
 "password"="yyy";
}

Invoke-WebRequest -Uri http://localhost:3000/ -Method POST -Body $params

Run yarn euid in the terminal of the TCPortal code, then run the above script in ISE. Make sure the app does not crash, but instead logs the error and stays running. Go to the EUID TCPortal on localhost:3000, enter a valid email, and make sure the app is still working after the error.

@ashleysmithTTD
Copy link
Contributor Author

I was going to use the error handler onError in www.ts however it has a check to throw an error if it is not an HttpError, which this is not. Instead, since that function uses logger, I made the catch for this error to be a logger statement also.

if (!handler) {
throw new Error(`invalid step ${step}`);
catch (e) {
if (e instanceof Error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what else might e be an instance of here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yep - I don't need this line

if (!step) {
throw new Error('no step');
try {
const { step } = DefaultRouteRequest.parse(req.body);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kindof wondering if maybe the try/catch should only wrap this line? Like below you're throwing in a couple of other cases that this new block will catch. I'm not sure that's what you want to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the step variable being used in the rest of the lines (except the await handler line), wouldn't they all have to be in the try block because of this? I was getting an error by only having the first line in try I think. I can move await handler outside the try catch block

@ashleysmithTTD ashleysmithTTD merged commit 31cd285 into main Jul 30, 2024
3 checks passed
@ashleysmithTTD ashleysmithTTD deleted the ans-UID2-2107-tcportal-error-fix-botnet-traffic branch July 30, 2024 16:26
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.

2 participants