mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
30 lines
710 B
TypeScript
30 lines
710 B
TypeScript
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
export type AuthMode = 'none' | 'cookie' | 'bearer';
|
|
|
|
export type RequestOptions<B = unknown> = {
|
|
method?: HttpMethod;
|
|
body?: B;
|
|
query?: Record<string, unknown>;
|
|
headers?: Record<string, string>;
|
|
auth?: AuthMode; // 'cookie' | 'bearer' | 'none'
|
|
token?: string; // required if auth === 'bearer'
|
|
timeoutMs?: number;
|
|
responseType?:
|
|
| 'arraybuffer'
|
|
| 'blob'
|
|
| 'document'
|
|
| 'json'
|
|
| 'text'
|
|
| 'stream';
|
|
};
|
|
|
|
export class HttpError extends Error {
|
|
constructor(
|
|
public status: number,
|
|
public code?: string,
|
|
public data?: unknown
|
|
) {
|
|
super(`HTTP ${status}${code ? ` ${code}` : ''}`);
|
|
}
|
|
}
|