-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientBase.ts
32 lines (27 loc) · 1.08 KB
/
ClientBase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export class ClientBase {
/**
* authorization token value
*/
public static authToken: string | null = null
constructor() {
}
setAuthToken(token: string | null) {
ClientBase.authToken = token;
}
protected transformOptions(options: RequestInit): Promise<RequestInit> {
if (ClientBase.authToken && options.headers) {
const headers = options.headers as Record<string, string>;
headers["Authorization"] = "bearer " + ClientBase.authToken
options.headers = headers
} else {
console.warn("Authorization token have not been set please authorize first.");
}
return Promise.resolve(options);
}
protected transformResult(url: string, response: Response, processor: (response: Response) => any) {
// TODO: Return own result or throw exception to change default processing behavior,
// or call processor function to run the default processing logic
console.log("Service call: " + url);
return processor(response);
}
}