Skip to content

Add non-object error handling for API response - #9

Open
eljeffeg wants to merge 7 commits into
polarityio:developfrom
eljeffeg:master
Open

Add non-object error handling for API response#9
eljeffeg wants to merge 7 commits into
polarityio:developfrom
eljeffeg:master

Conversation

@eljeffeg

Copy link
Copy Markdown

This commit addresses a TypeError: Cannot read properties of undefined (reading 'error') that can occur when the API returns an unexpected status code without a JSON body. The previous handleRestError function did not properly validate the body object, causing the application to error.

Jon Penwood and others added 7 commits January 23, 2023 11:17
Updating Github Actions & Adding config.json
… Machine Readability

Creating Release with Dereferenced Symlinks, `polarityIntegrationUuid`, & No Dev Dependencies for Machine Readability
… Machine Readability

Removing `-beta` from `version` field in `package.json` & `package-lock.json`
Removing rejectUnauthorized from config files
INT-1107: Converted expandable types & Removed `requestOptions` from `config.json`
INT-1426: Improve error handling, update dependencies, remove use of summary component
This commit addresses a `TypeError: Cannot read properties of undefined (reading 'error')` that can occur when the API returns an unexpected status code without a JSON body. The previous handleRestError function did not properly validate the body object, causing the application to error.
@CitadelOfBlairs

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Comment thread integration.js
error: body ? body : 'Unknown Error',
detail:
body && body.error && body.message
body && typeof body === 'object' && body.error && body.message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@eljeffeg Thank you for the PR! Just curious on this but were you seeing a case where the existing guard was failing? The specific error message you referenced suggests body was undefined which should be handled by the check that is currently in place.

TypeError: Cannot read properties of undefined (reading 'error')

We're actually forcing the request library we're using to parse the body as json (via the json: true attribute on the request options), so if body wasn't valid JSON I think we would actually get a different error entirely.

Finally, can you update the PR to target the develop branch?

@eljeffeg eljeffeg Oct 15, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, I got the error while trying to run it on https://polarityscribe.polarity.io/. I then loaded it up locally and got the error Unexpected HTTP Status Code 500 received.. Maybe I'm doing something wrong, but I verified it using curl curl -X GET 'https://api.threatminer.org/v2/sample.php?q=dd2b6e3aa75de8460730862f2dc739537734a7dfc9e673b6a23ee58430348ddf&rt=1' -v -i. ThreatMiner is returning a 500. I tried a few different hashes, even going directly to the site https://api.threatminer.org/v2/sample.php?q=dd2b6e3aa75de8460730862f2dc739537734a7dfc9e673b6a23ee58430348ddf&rt=1

Looks like a problem with ThreatMiner. So I don't think there is anything wrong with the integration from what I can tell unless ThreatMiner changed their API; we just weren't handling the case that an error would return without a proper body.

@eljeffeg
eljeffeg changed the base branch from master to develop October 15, 2025 14:06
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.

5 participants