@crowdin/crowdin-api-client
Advanced tools
Comparing version 1.21.2 to 1.22.0
@@ -0,1 +1,2 @@ | ||
import { HttpClientError } from './http-client-error'; | ||
import { RetryConfig, RetryService } from './internal/retry'; | ||
@@ -120,2 +121,6 @@ /** | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export declare function handleHttpClientError(error: HttpClientError): never; | ||
export declare abstract class CrowdinApi { | ||
@@ -122,0 +127,0 @@ private static readonly CROWDIN_URL_SUFFIX; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isOptionalNumber = exports.isOptionalString = exports.CrowdinApi = exports.CrowdinValidationError = exports.CrowdinError = exports.BooleanInt = void 0; | ||
exports.isOptionalNumber = exports.isOptionalString = exports.CrowdinApi = exports.handleHttpClientError = exports.CrowdinValidationError = exports.CrowdinError = exports.BooleanInt = void 0; | ||
const axios_1 = require("axios"); | ||
const http_client_error_1 = require("./http-client-error"); | ||
const axiosProvider_1 = require("./internal/axios/axiosProvider"); | ||
const fetchClient_1 = require("./internal/fetch/fetchClient"); | ||
const fetchClientError_1 = require("./internal/fetch/fetchClientError"); | ||
const retry_1 = require("./internal/retry"); | ||
@@ -38,8 +41,15 @@ /** | ||
*/ | ||
function handleError(error = {}) { | ||
var _a, _b; | ||
if (Array.isArray(error.errors)) { | ||
function handleHttpClientError(error) { | ||
var _a, _b, _c, _d; | ||
const crowdinResponseErrors = error instanceof axios_1.AxiosError | ||
? (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors | ||
: error instanceof fetchClientError_1.FetchClientJsonPayloadError | ||
? error.jsonPayload && typeof error.jsonPayload === 'object' && 'errors' in error.jsonPayload | ||
? error.jsonPayload.errors | ||
: null | ||
: null; | ||
if (Array.isArray(crowdinResponseErrors)) { | ||
const validationCodes = []; | ||
const validationMessages = []; | ||
error.errors.forEach((e) => { | ||
crowdinResponseErrors.forEach((e) => { | ||
var _a; | ||
@@ -60,6 +70,13 @@ if (e.error.key && Array.isArray((_a = e.error) === null || _a === void 0 ? void 0 : _a.errors)) { | ||
} | ||
const message = ((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || 'Error occured'; | ||
const code = ((_b = error.error) === null || _b === void 0 ? void 0 : _b.code) || 500; | ||
throw new CrowdinError(message, code); | ||
if (error instanceof Error) { | ||
const code = error instanceof axios_1.AxiosError && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) | ||
? (_d = error.response) === null || _d === void 0 ? void 0 : _d.status | ||
: error instanceof fetchClientError_1.FetchClientJsonPayloadError | ||
? error.statusCode | ||
: 500; | ||
throw new CrowdinError(error.message, code); | ||
} | ||
throw new CrowdinError(`unknown http error: ${String(error)}`, 500); | ||
} | ||
exports.handleHttpClientError = handleHttpClientError; | ||
class CrowdinApi { | ||
@@ -200,18 +217,30 @@ /** | ||
get(url, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.get(url, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.get(url, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
delete(url, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.delete(url, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.delete(url, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
head(url, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.head(url, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.head(url, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
post(url, data, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.post(url, data, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.post(url, data, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
put(url, data, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.put(url, data, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.put(url, data, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
patch(url, data, config) { | ||
return this.retryService.executeAsyncFunc(() => this.httpClient.patch(url, data, config).catch(e => handleError(e))); | ||
return this.retryService | ||
.executeAsyncFunc(() => this.httpClient.patch(url, data, config)) | ||
.catch((err) => handleHttpClientError((0, http_client_error_1.toHttpClientError)(err))); | ||
} | ||
@@ -218,0 +247,0 @@ } |
@@ -33,5 +33,5 @@ "use strict"; | ||
return Promise.resolve(response.data); | ||
}, error => { | ||
}, (error) => { | ||
this.pendingRequests = Math.max(0, this.pendingRequests - 1); | ||
return Promise.reject(error.response.data); | ||
return Promise.reject(error); | ||
}); | ||
@@ -38,0 +38,0 @@ } |
@@ -0,1 +1,6 @@ | ||
/// <reference lib="dom" /> | ||
/** | ||
* Import DOM types for this module _just_ to expose adequate types for | ||
* fetch interfaces | ||
*/ | ||
import { HttpClient } from '../..'; | ||
@@ -2,0 +7,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FetchClient = void 0; | ||
const fetchClientError_1 = require("./fetchClientError"); | ||
/** | ||
@@ -61,3 +62,3 @@ * @internal | ||
else { | ||
throw json; | ||
throw new fetchClientError_1.FetchClientJsonPayloadError(res.statusText, json, res.status); | ||
} | ||
@@ -64,0 +65,0 @@ }) |
{ | ||
"name": "@crowdin/crowdin-api-client", | ||
"version": "1.21.2", | ||
"version": "1.22.0", | ||
"description": "JavaScript library for Crowdin API v2.", | ||
@@ -16,3 +16,3 @@ "main": "out/index.js", | ||
"prepare": "husky install", | ||
"test": "jest --config jestconfig.json", | ||
"test": "jest", | ||
"build": "tsc -p ./", | ||
@@ -22,3 +22,3 @@ "watch": "tsc -watch -p ./", | ||
"lint-ci": "eslint \"{src,tests}/**/*.{js,ts}\"", | ||
"test-coverage": "jest --config jestconfig.json --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html", | ||
"test-coverage": "jest --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html", | ||
"generate-docs": "typedoc src/index.ts --options .docs-config/typedoc.json" | ||
@@ -30,2 +30,5 @@ }, | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^1" | ||
}, | ||
"devDependencies": { | ||
@@ -51,5 +54,2 @@ "@types/jest": "^27.0.0", | ||
}, | ||
"dependencies": { | ||
"axios": "0.21.3" | ||
}, | ||
"engines": { | ||
@@ -64,8 +64,2 @@ "node": ">=12.9.0" | ||
}, | ||
"jest": { | ||
"coverageReporters": [ | ||
"text", | ||
"cobertura" | ||
] | ||
}, | ||
"bugs": { | ||
@@ -72,0 +66,0 @@ "url": "https://github.com/crowdin/crowdin-api-client-js/issues" |
@@ -97,3 +97,3 @@ [<p align='center'><img src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' data-canonical-src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' width='150' height='150' align='center'/></p>](https://crowdin.com) | ||
}; | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileDate); | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileData); | ||
const file = await sourceFilesApi.createFile(projectId, { | ||
@@ -187,3 +187,3 @@ name: 'file1.json', | ||
}; | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileDate); | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileData); | ||
const file = await sourceFilesApi.createFile(projectId, { | ||
@@ -274,3 +274,3 @@ name: 'file1.json', | ||
}; | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileDate); | ||
const storage = await uploadStorageApi.addStorage('file1.json', fileData); | ||
const file = await sourceFilesApi.createFile(projectId, { | ||
@@ -277,0 +277,0 @@ name: 'file1.json', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355010
67
8038
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.9(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.21.3(transitive)
Updatedaxios@^1