@hubspot/local-dev-lib 0.2.1 → 0.2.2-experimental.0
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.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +11 -11
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +17 -17
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -4
- package/api/functions.js +22 -11
- package/api/github.d.ts +7 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +8 -16
- package/api/localDevAuth.js +34 -13
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +31 -24
- package/api/projects.js +164 -44
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +15 -11
- package/config/CLIConfiguration.js +175 -90
- package/config/configFile.js +13 -21
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +5 -4
- package/config/config_DEPRECATED.d.ts +6 -8
- package/config/config_DEPRECATED.js +79 -25
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +13 -8
- package/config/index.js +97 -57
- package/config/migrate.d.ts +20 -0
- package/config/migrate.js +150 -0
- package/constants/config.d.ts +25 -1
- package/constants/config.js +32 -3
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +6 -3
- package/http/getAxiosConfig.js +51 -7
- package/http/index.d.ts +11 -12
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +384 -386
- package/lib/archive.d.ts +2 -8
- package/lib/archive.js +34 -30
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +49 -51
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +4 -15
- package/lib/cms/modules.js +81 -78
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +53 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -18
- package/lib/cms/watch.js +63 -68
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.d.ts +2 -6
- package/lib/fileManager.js +54 -65
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +67 -88
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +12 -14
- package/lib/github.js +70 -35
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +2 -5
- package/lib/oauth.js +14 -25
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +8 -11
- package/lib/personalAccessKey.js +76 -38
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/trackUsage.js +18 -11
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +5 -27
- package/models/OAuth2Manager.js +41 -64
- package/package.json +35 -35
- package/types/Accounts.d.ts +103 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +12 -11
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +37 -47
- package/types/Schemas.d.ts +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +13 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +22 -16
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/errors/apiErrors.d.ts +0 -19
- package/errors/apiErrors.js +0 -179
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -27
- package/errors/standardErrors.js +0 -59
- package/lang/lang/en.json +0 -401
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -71
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -7
- package/utils/logger.d.ts +0 -5
- package/utils/logger.js +0 -23
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
- /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/errors/apiErrors.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwApiUploadError = exports.throwApiError = exports.throwAxiosErrorWithContext = exports.isSpecifiedHubSpotAuthError = exports.isApiUploadValidationError = exports.isGatingError = exports.isMissingScopeError = void 0;
|
|
4
|
-
const api_1 = require("../constants/api");
|
|
5
|
-
const lang_1 = require("../utils/lang");
|
|
6
|
-
const standardErrors_1 = require("./standardErrors");
|
|
7
|
-
const i18nKey = 'errors.apiErrors';
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
function isMissingScopeError(err) {
|
|
10
|
-
return (err.isAxiosError &&
|
|
11
|
-
err.status === 403 &&
|
|
12
|
-
!!err.response &&
|
|
13
|
-
err.response.data.category === 'MISSING_SCOPES');
|
|
14
|
-
}
|
|
15
|
-
exports.isMissingScopeError = isMissingScopeError;
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
function isGatingError(err) {
|
|
18
|
-
return (err.isAxiosError &&
|
|
19
|
-
err.status === 403 &&
|
|
20
|
-
!!err.response &&
|
|
21
|
-
err.response.data.category === 'GATED');
|
|
22
|
-
}
|
|
23
|
-
exports.isGatingError = isGatingError;
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
function isApiUploadValidationError(err) {
|
|
26
|
-
return (err.isAxiosError &&
|
|
27
|
-
err.status === 400 &&
|
|
28
|
-
!!err.response &&
|
|
29
|
-
!!(err.response?.data?.message || !!err.response?.data?.errors));
|
|
30
|
-
}
|
|
31
|
-
exports.isApiUploadValidationError = isApiUploadValidationError;
|
|
32
|
-
function isSpecifiedHubSpotAuthError(err, { status, category, subCategory }) {
|
|
33
|
-
const statusCodeErr = !status || err.status === status;
|
|
34
|
-
const categoryErr = !category || err.category === category;
|
|
35
|
-
const subCategoryErr = !subCategory || err.subCategory === subCategory;
|
|
36
|
-
return Boolean(err.name === 'HubSpotAuthError' &&
|
|
37
|
-
statusCodeErr &&
|
|
38
|
-
categoryErr &&
|
|
39
|
-
subCategoryErr);
|
|
40
|
-
}
|
|
41
|
-
exports.isSpecifiedHubSpotAuthError = isSpecifiedHubSpotAuthError;
|
|
42
|
-
function parseValidationErrors(responseData = { errors: [], message: '' }) {
|
|
43
|
-
const errorMessages = [];
|
|
44
|
-
const { errors, message } = responseData;
|
|
45
|
-
if (message) {
|
|
46
|
-
errorMessages.push(message);
|
|
47
|
-
}
|
|
48
|
-
if (errors) {
|
|
49
|
-
const specificErrors = errors.map(error => {
|
|
50
|
-
let errorMessage = error.message;
|
|
51
|
-
if (error.errorTokens && error.errorTokens.line) {
|
|
52
|
-
errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
|
|
53
|
-
}
|
|
54
|
-
return errorMessage;
|
|
55
|
-
});
|
|
56
|
-
errorMessages.push(...specificErrors);
|
|
57
|
-
}
|
|
58
|
-
return errorMessages;
|
|
59
|
-
}
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
function logValidationErrors(error) {
|
|
62
|
-
const validationErrorMessages = parseValidationErrors(error?.response?.data);
|
|
63
|
-
if (validationErrorMessages.length) {
|
|
64
|
-
(0, standardErrors_1.throwError)(new Error(validationErrorMessages.join(' '), { cause: error }));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @throws
|
|
69
|
-
*/
|
|
70
|
-
function throwAxiosErrorWithContext(
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
-
error, context = {}) {
|
|
73
|
-
const { status } = error;
|
|
74
|
-
const method = error.config?.method;
|
|
75
|
-
const { projectName } = context;
|
|
76
|
-
const isPutOrPost = method === 'put' || method === 'post';
|
|
77
|
-
const action = method && (api_1.HTTP_METHOD_VERBS[method] || api_1.HTTP_METHOD_VERBS.get);
|
|
78
|
-
const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
|
|
79
|
-
api_1.HTTP_METHOD_PREPOSITIONS.get;
|
|
80
|
-
const request = context.request
|
|
81
|
-
? `${action} ${preposition} "${context.request}"`
|
|
82
|
-
: action;
|
|
83
|
-
const messageDetail = request && context.accountId
|
|
84
|
-
? (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
|
|
85
|
-
request,
|
|
86
|
-
accountId: context.accountId,
|
|
87
|
-
})
|
|
88
|
-
: 'request';
|
|
89
|
-
const errorMessage = [];
|
|
90
|
-
if (isPutOrPost && context.payload) {
|
|
91
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
|
|
92
|
-
}
|
|
93
|
-
const isProjectMissingScopeError = isMissingScopeError(error) && projectName;
|
|
94
|
-
const isProjectGatingError = isGatingError(error) && projectName;
|
|
95
|
-
switch (status) {
|
|
96
|
-
case 400:
|
|
97
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
|
|
98
|
-
break;
|
|
99
|
-
case 401:
|
|
100
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
|
|
101
|
-
break;
|
|
102
|
-
case 403:
|
|
103
|
-
if (isProjectMissingScopeError) {
|
|
104
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403MissingScope`, {
|
|
105
|
-
accountId: context.accountId || '',
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
else if (isProjectGatingError) {
|
|
109
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403Gating`, {
|
|
110
|
-
accountId: context.accountId || '',
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403`, { messageDetail }));
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
case 404:
|
|
118
|
-
if (context.request) {
|
|
119
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404Request`, {
|
|
120
|
-
action: action || 'request',
|
|
121
|
-
request: context.request,
|
|
122
|
-
account: context.accountId || '',
|
|
123
|
-
}));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
case 429:
|
|
130
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
|
|
131
|
-
break;
|
|
132
|
-
case 503:
|
|
133
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
|
|
134
|
-
break;
|
|
135
|
-
default:
|
|
136
|
-
if (status && status >= 500 && status < 600) {
|
|
137
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
|
|
138
|
-
}
|
|
139
|
-
else if (status && status >= 400 && status < 500) {
|
|
140
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (error?.response?.data?.message &&
|
|
148
|
-
!isProjectMissingScopeError &&
|
|
149
|
-
!isProjectGatingError) {
|
|
150
|
-
errorMessage.push(error.response.data.message);
|
|
151
|
-
}
|
|
152
|
-
if (error?.response?.data?.errors) {
|
|
153
|
-
error.response.data.errors.forEach((err) => {
|
|
154
|
-
errorMessage.push('\n- ' + err.message);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
(0, standardErrors_1.throwError)(new Error(errorMessage.join(' '), { cause: error }));
|
|
158
|
-
}
|
|
159
|
-
exports.throwAxiosErrorWithContext = throwAxiosErrorWithContext;
|
|
160
|
-
/**
|
|
161
|
-
* @throws
|
|
162
|
-
*/
|
|
163
|
-
function throwApiError(error, context = {}) {
|
|
164
|
-
if (error.isAxiosError) {
|
|
165
|
-
throwAxiosErrorWithContext(error, context);
|
|
166
|
-
}
|
|
167
|
-
(0, standardErrors_1.throwError)(error);
|
|
168
|
-
}
|
|
169
|
-
exports.throwApiError = throwApiError;
|
|
170
|
-
/**
|
|
171
|
-
* @throws
|
|
172
|
-
*/
|
|
173
|
-
function throwApiUploadError(error, context = {}) {
|
|
174
|
-
if (isApiUploadValidationError(error)) {
|
|
175
|
-
logValidationErrors(error);
|
|
176
|
-
}
|
|
177
|
-
throwApiError(error, context);
|
|
178
|
-
}
|
|
179
|
-
exports.throwApiUploadError = throwApiUploadError;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwFileSystemError = void 0;
|
|
4
|
-
const lang_1 = require("../utils/lang");
|
|
5
|
-
const standardErrors_1 = require("./standardErrors");
|
|
6
|
-
const i18nKey = 'errors.fileSystemErrors';
|
|
7
|
-
/**
|
|
8
|
-
* @throws
|
|
9
|
-
*/
|
|
10
|
-
function throwFileSystemError(error, context) {
|
|
11
|
-
let fileAction = '';
|
|
12
|
-
if (context.read) {
|
|
13
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
|
|
14
|
-
}
|
|
15
|
-
else if (context.write) {
|
|
16
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
|
|
20
|
-
}
|
|
21
|
-
const filepath = context.filepath
|
|
22
|
-
? `"${context.filepath}"`
|
|
23
|
-
: (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
|
|
24
|
-
const message = [(0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath })];
|
|
25
|
-
// Many `fs` errors will be `SystemError`s
|
|
26
|
-
if ((0, standardErrors_1.isSystemError)(error)) {
|
|
27
|
-
message.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, { errorMessage: error.message }));
|
|
28
|
-
}
|
|
29
|
-
throw new Error(message.join(' '), { cause: error });
|
|
30
|
-
}
|
|
31
|
-
exports.throwFileSystemError = throwFileSystemError;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BaseError } from '../types/Error';
|
|
2
|
-
import { LangKey } from '../types/Lang';
|
|
3
|
-
import { AxiosError } from 'axios';
|
|
4
|
-
export declare function isSystemError(err: BaseError): boolean;
|
|
5
|
-
export declare function isFatalError(err: BaseError): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* @throws
|
|
8
|
-
*/
|
|
9
|
-
export declare function throwErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
10
|
-
[key: string]: string | number;
|
|
11
|
-
}, cause?: BaseError): never;
|
|
12
|
-
/**
|
|
13
|
-
* @throws
|
|
14
|
-
*/
|
|
15
|
-
export declare function throwTypeErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
16
|
-
[key: string]: string | number;
|
|
17
|
-
}, cause?: BaseError): never;
|
|
18
|
-
/**
|
|
19
|
-
* @throws
|
|
20
|
-
*/
|
|
21
|
-
export declare function throwAuthErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
22
|
-
[key: string]: string | number;
|
|
23
|
-
}, cause?: AxiosError): never;
|
|
24
|
-
/**
|
|
25
|
-
* @throws
|
|
26
|
-
*/
|
|
27
|
-
export declare function throwError(error: BaseError): never;
|
package/errors/standardErrors.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwError = exports.throwAuthErrorWithMessage = exports.throwTypeErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
|
|
4
|
-
const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
|
|
5
|
-
const lang_1 = require("../utils/lang");
|
|
6
|
-
function isSystemError(err) {
|
|
7
|
-
return err.errno != null && err.code != null && err.syscall != null;
|
|
8
|
-
}
|
|
9
|
-
exports.isSystemError = isSystemError;
|
|
10
|
-
function isFatalError(err) {
|
|
11
|
-
return err instanceof HubSpotAuthError_1.HubSpotAuthError;
|
|
12
|
-
}
|
|
13
|
-
exports.isFatalError = isFatalError;
|
|
14
|
-
function genericThrowErrorWithMessage(ErrorType, identifier, interpolation, cause) {
|
|
15
|
-
const message = (0, lang_1.i18n)(identifier, interpolation);
|
|
16
|
-
if (cause) {
|
|
17
|
-
throw new ErrorType(message, { cause });
|
|
18
|
-
}
|
|
19
|
-
throw new ErrorType(message);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @throws
|
|
23
|
-
*/
|
|
24
|
-
function throwErrorWithMessage(identifier, interpolation, cause) {
|
|
25
|
-
genericThrowErrorWithMessage(Error, identifier, interpolation, cause);
|
|
26
|
-
}
|
|
27
|
-
exports.throwErrorWithMessage = throwErrorWithMessage;
|
|
28
|
-
/**
|
|
29
|
-
* @throws
|
|
30
|
-
*/
|
|
31
|
-
function throwTypeErrorWithMessage(identifier, interpolation, cause) {
|
|
32
|
-
genericThrowErrorWithMessage(TypeError, identifier, interpolation, cause);
|
|
33
|
-
}
|
|
34
|
-
exports.throwTypeErrorWithMessage = throwTypeErrorWithMessage;
|
|
35
|
-
/**
|
|
36
|
-
* @throws
|
|
37
|
-
*/
|
|
38
|
-
function throwAuthErrorWithMessage(identifier, interpolation, cause) {
|
|
39
|
-
genericThrowErrorWithMessage(
|
|
40
|
-
// @ts-expect-error HubSpotAuthError is not callable
|
|
41
|
-
HubSpotAuthError_1.HubSpotAuthError, identifier, interpolation, cause);
|
|
42
|
-
}
|
|
43
|
-
exports.throwAuthErrorWithMessage = throwAuthErrorWithMessage;
|
|
44
|
-
/**
|
|
45
|
-
* @throws
|
|
46
|
-
*/
|
|
47
|
-
function throwError(error) {
|
|
48
|
-
// Error or Error subclass
|
|
49
|
-
const message = error.name && error.name !== 'Error'
|
|
50
|
-
? [(0, lang_1.i18n)('errors.generic', { name: error.name })]
|
|
51
|
-
: [];
|
|
52
|
-
[error.message, error.reason].forEach(msg => {
|
|
53
|
-
if (msg) {
|
|
54
|
-
message.push(msg);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
throw new Error(message.join(' '), { cause: error });
|
|
58
|
-
}
|
|
59
|
-
exports.throwError = throwError;
|