mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
feat: flexible response parsing in HTTP client (allows text now)
This commit is contained in:
@@ -75,16 +75,17 @@ export class BaseHttpClient {
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
// Parse response - handle empty body (common for DELETE)
|
||||
// Parse response based on responseType
|
||||
const text = await response.text();
|
||||
const data = text ? JSON.parse(text) : null;
|
||||
const responseType = options?.responseType ?? 'json';
|
||||
const data = responseType === 'text' ? text : (text ? JSON.parse(text) : null);
|
||||
|
||||
// Check for HTTP errors
|
||||
if (!response.ok) {
|
||||
const error = new HttpError(
|
||||
`HTTP ${response.status}: ${response.statusText}`,
|
||||
response.status,
|
||||
data
|
||||
responseType === 'json' ? data : text
|
||||
);
|
||||
|
||||
// Retry on specific status codes
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface RequestOptions {
|
||||
headers?: Record<string, string>; // Additional headers for this request
|
||||
timeout?: number; // Override timeout for this request
|
||||
signal?: AbortSignal; // Abort signal for cancellation
|
||||
responseType?: 'json' | 'text'; // Response parsing type (default: 'json')
|
||||
}
|
||||
|
||||
export class HttpError extends Error {
|
||||
|
||||
Reference in New Issue
Block a user