axios+telemetry cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import axios, { type AxiosError } from 'axios'
|
||||
import { isHttpError, nativeRequest } from '../../utils/http.js'
|
||||
import type { StdoutMessage } from 'src/entrypoints/sdk/controlTypes.js'
|
||||
import { logForDebugging } from '../../utils/debug.js'
|
||||
import { logForDiagnosticsNoPII } from '../../utils/diagLogs.js'
|
||||
@@ -212,20 +212,17 @@ export class HybridTransport extends WebSocketTransport {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
let response
|
||||
let response: { status: number; data: unknown }
|
||||
try {
|
||||
response = await axios.post(
|
||||
this.postUrl,
|
||||
{ events },
|
||||
{
|
||||
headers,
|
||||
validateStatus: () => true,
|
||||
timeout: POST_TIMEOUT_MS,
|
||||
},
|
||||
)
|
||||
response = await nativeRequest(this.postUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: { events },
|
||||
timeout: POST_TIMEOUT_MS,
|
||||
responseType: 'json',
|
||||
})
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError
|
||||
logForDebugging(`HybridTransport: POST error: ${axiosError.message}`)
|
||||
logForDebugging(`HybridTransport: POST error: ${error instanceof Error ? error.message : 'unknown'}`)
|
||||
logForDiagnosticsNoPII('warn', 'cli_hybrid_post_network_error')
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import axios, { type AxiosError } from 'axios'
|
||||
import { isHttpError, nativeRequest } from '../../utils/http.js'
|
||||
import type { StdoutMessage } from 'src/entrypoints/sdk/controlTypes.js'
|
||||
import { logForDebugging } from '../../utils/debug.js'
|
||||
import { logForDiagnosticsNoPII } from '../../utils/diagLogs.js'
|
||||
@@ -590,9 +590,11 @@ export class SSETransport implements Transport {
|
||||
|
||||
for (let attempt = 1; attempt <= POST_MAX_RETRIES; attempt++) {
|
||||
try {
|
||||
const response = await axios.post(this.postUrl, message, {
|
||||
const response = await nativeRequest(this.postUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
validateStatus: alwaysValidStatus,
|
||||
body: message,
|
||||
responseType: 'json',
|
||||
})
|
||||
|
||||
if (response.status === 200 || response.status === 201) {
|
||||
@@ -603,7 +605,6 @@ export class SSETransport implements Transport {
|
||||
logForDebugging(
|
||||
`SSETransport: POST ${response.status} body=${jsonStringify(response.data).slice(0, 200)}`,
|
||||
)
|
||||
// 4xx errors (except 429) are permanent - don't retry
|
||||
if (
|
||||
response.status >= 400 &&
|
||||
response.status < 500 &&
|
||||
@@ -618,7 +619,6 @@ export class SSETransport implements Transport {
|
||||
return
|
||||
}
|
||||
|
||||
// 429 or 5xx - retry
|
||||
logForDebugging(
|
||||
`SSETransport: POST returned ${response.status}, attempt ${attempt}/${POST_MAX_RETRIES}`,
|
||||
)
|
||||
@@ -627,9 +627,8 @@ export class SSETransport implements Transport {
|
||||
attempt,
|
||||
})
|
||||
} catch (error) {
|
||||
const axiosError = error as AxiosError
|
||||
logForDebugging(
|
||||
`SSETransport: POST error: ${axiosError.message}, attempt ${attempt}/${POST_MAX_RETRIES}`,
|
||||
`SSETransport: POST error: ${error instanceof Error ? error.message : 'unknown'}, attempt ${attempt}/${POST_MAX_RETRIES}`,
|
||||
)
|
||||
logForDiagnosticsNoPII('warn', 'cli_sse_post_network_error', {
|
||||
attempt,
|
||||
|
||||
Reference in New Issue
Block a user