@pushwoosh/http-client 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +16 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -27,12 +27,18 @@
27
27
  import { HttpClient } from './http-client';
28
28
 
29
29
  const httpClient = new HttpClient({
30
+ errorMiddleware: (error: unknown): Promise<never> | never => {
31
+ // какие-то действия над ошибками
32
+ },
30
33
  urls: {
31
34
  authorize: 'https://sso.pushwoosh.com/authorize', // адрес старта сеанса
32
35
  token: 'https://sso.pushwoosh.com/token', // адрес для получения или обновления пары токенов для авторизации в приватных API
33
36
  logout: 'https://sso.pushwoosh.com/logout', // адрес для завершения сеанса
34
37
  },
35
38
  clientId: 'APP_FRONT', // уникальный идентификатор клиента (связан с доменом)
39
+ cookie: {
40
+ domain: '.pushwoosh.com', // на какой домен будут выписываться cookies
41
+ },
36
42
  })
37
43
  ```
38
44
 
@@ -128,9 +134,14 @@ curl 'https://app.pushwoosh.com/entrypoint' \
128
134
  Можно выполнить следующей конструкцией:
129
135
  ```typescript
130
136
  try {
131
- const result = httpClient.get<never, never, never>('/entrypoint', {
137
+ const result = httpClient.get<never, never, { some: string }>('/entrypoint', {
132
138
  withAuthorization: true,
133
139
  withCredentials: false,
140
+ responseMiddleware: (response: Response): { some: string } => { // если стандартный middleware для разбора ответа от сервера не подходит
141
+ const jsonResponse = httpClient.baseResponseMiddleware(response);
142
+ const result = httpClient.baseResponseMiddleware(response);
143
+ return result;
144
+ },
134
145
  });
135
146
  } catch (error: unknown) {
136
147
  // TODO: error capture
@@ -199,3 +210,7 @@ try {
199
210
  `ServiceUnavailableError (extends HttpClientError)` - Класс описывающий ошибку "Сервис недоступен"
200
211
 
201
212
  `GatewayTimeoutError (extends HttpClientError)` - Класс описывающий ошибку "Вышло время ожидания ответа"
213
+
214
+ #### Ошибки связанные с валидацией ответа:
215
+
216
+ `ValidationError (extends HttpClientError)` - Класс описывающий ошибку валидации
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/http-client",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",