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

packages: core: http: Return raw response data if JSON cannot parse #152

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions packages/core/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ export async function postRelayerRaw(url: string, body: any, headers = {}) {
try {
const response = await axios.post(url, body, {
headers,
transformResponse: (data) => parseBigJSON(data),
validateStatus: null, // Allow any status code to pass through
transformResponse: (data) => {
try {
return parseBigJSON(data)
} catch {
// If parsing fails, return raw data
return data
}
},
})
// console.log(`POST ${url} with body: `, body, "response: ", response.data)
// Process the response data as needed
return response.data // Assuming the function should return the response data

// For non-2xx responses, throw error with raw data
if (response.status < 200 || response.status >= 300) {
throw new BaseError(response.data)
}

return response.data
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
Expand Down
Loading