Revert "fix(api): fix api block"#953
Conversation
This reverts commit 8016af6.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
There was a problem hiding this comment.
Greptile Summary
This PR reverts PR #951, which was a bug fix for API block functionality. The revert affects two core files in the tools system that handle HTTP requests and response processing.
In apps/sim/tools/index.ts, the revert removes a response cloning mechanism that was added to prevent "Response body already read" errors. The original fix created responseForTransform = response.clone() to ensure the response body could be read both during error checking (lines 407-414) and later during transformation. Without this cloning, the response body will be consumed during error checking, causing failures when transformResponse tries to read it again.
In apps/sim/tools/http/request.ts, the revert removes enhanced error handling in the HTTP request tool's transformResponse method. The original fix replaced a simple fallback to response.text() with more descriptive error messaging when JSON/text parsing failed. This revert returns to the simpler approach that preserves raw response data but loses valuable debugging context.
Both changes affect core infrastructure used across the application for API integrations. The tools system is fundamental to the platform's ability to interact with external services like GitHub, as evidenced by tools like the GitHub PR reader that rely on proper response handling. The revert suggests the original fix may have introduced unintended side effects or compatibility issues with existing integrations.
Confidence score: 1/5
- This PR will very likely cause runtime errors due to Response body consumption issues
- Score reflects high risk of breaking existing API integrations that rely on transformResponse functionality
- Pay close attention to apps/sim/tools/index.ts where the response cloning removal will cause failures
2 files reviewed, 2 comments
| if (tool.transformResponse) { | ||
| try { | ||
| const data = await tool.transformResponse(responseForTransform, params) | ||
| const data = await tool.transformResponse(response, params) | ||
| return data |
There was a problem hiding this comment.
logic: This will throw 'body already read' error since the response body was consumed at line 408 for error checking
| if (tool.transformResponse) { | |
| try { | |
| const data = await tool.transformResponse(responseForTransform, params) | |
| const data = await tool.transformResponse(response, params) | |
| return data | |
| if (tool.transformResponse) { | |
| try { | |
| const data = await tool.transformResponse(responseForErrorCheck, params) | |
| return data |
| } catch (error) { | ||
| // If response body reading fails, we can't retry reading - just use error message | ||
| data = `Failed to parse response: ${error instanceof Error ? error.message : String(error)}` | ||
| data = await response.text() |
There was a problem hiding this comment.
logic: This fallback assumes response.text() can still be called after a failed response.json() call, but response bodies can only be consumed once. This could throw an error.
| data = await response.text() | |
| data = `Failed to parse response: ${error instanceof Error ? error.message : String(error)}` |
This reverts commit 8016af6.
Reverts #951