-
Notifications
You must be signed in to change notification settings - Fork 7
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
ashleysmithTTD
merged 6 commits into
main
from
ans-UID2-2107-tcportal-error-fix-botnet-traffic
Jul 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4d7a39
added try catch block
ashleysmithTTD 0dd4950
remove instance of check
ashleysmithTTD 4ab7e41
define step outside try catch
ashleysmithTTD 66afa08
no spaces needed
ashleysmithTTD c4e9d9c
put back in the space here
ashleysmithTTD 2327b96
log other errors too
ashleysmithTTD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,17 +138,28 @@ const DefaultRouteRequest = z.object({ | |
}); | ||
|
||
const defaultRouteHandler: RequestHandler<{}, {}, z.infer<typeof DefaultRouteRequest>> = async (req, res, next) => { | ||
const { step } = DefaultRouteRequest.parse(req.body); | ||
if (!step) { | ||
throw new Error('no step'); | ||
try { | ||
const { step } = DefaultRouteRequest.parse(req.body); | ||
if (!step) { | ||
throw new Error('no step'); | ||
} | ||
const handler = Object.prototype.hasOwnProperty.call(steps, step) && steps[step]; | ||
if (!handler) { | ||
throw new Error(`invalid step ${step}`); | ||
} | ||
|
||
await handler(req, res, next); | ||
} | ||
|
||
const handler = Object.prototype.hasOwnProperty.call(steps, step) && steps[step]; | ||
if (!handler) { | ||
throw new Error(`invalid step ${step}`); | ||
catch (e) { | ||
if (e instanceof Error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what else might e be an instance of here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yep - I don't need this line |
||
logger.log('error', `error while parsing the request`); | ||
} | ||
|
||
} | ||
|
||
await handler(req, res, next); | ||
|
||
|
||
|
||
}; | ||
|
||
router.post('/', defaultRouteHandler); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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