@wireapp/api-client 27.75.4 → 27.75.6

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.
@@ -1,7 +1,23 @@
1
- import { BackendError } from './';
1
+ import { StatusCodes as StatusCode } from 'http-status-codes';
2
+ import { BackendError, BackendErrorLabel } from './';
3
+ type BackendErrorWithLabel = BackendError & {
4
+ label: BackendErrorLabel;
5
+ };
6
+ type ErrorBuilder = (e: BackendErrorWithLabel) => BackendError;
7
+ type ErrorLabelToBuilderMap = Partial<Record<BackendErrorLabel, ErrorBuilder>>;
8
+ type StatusCodeToLabelMap = Partial<Record<StatusCode, ErrorLabelToBuilderMap>>;
2
9
  export declare class BackendErrorMapper {
3
- static get ERRORS(): Record<number, Record<string, Record<string, BackendError>>>;
10
+ /**
11
+ * Baseline/default handler for each (code, label). Used when no message variant matches.
12
+ */
13
+ static defaultHandlers: StatusCodeToLabelMap;
14
+ /**
15
+ * Message-specific variants for known texts under a given (code,label).
16
+ * Provides finer granularity when wording matches; otherwise we fall back to defaultHandlers.
17
+ */
18
+ private static messageVariantHandlers;
4
19
  private static logUnmapped;
5
20
  static map(error: BackendError): BackendError;
6
21
  }
22
+ export {};
7
23
  //# sourceMappingURL=BackendErrorMapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BackendErrorMapper.d.ts","sourceRoot":"","sources":["../../src/http/BackendErrorMapper.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAC,YAAY,EAAgC,MAAM,IAAI,CAAC;AAE/D,qBAAa,kBAAkB;IAC7B,WAAkB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CA6DvF;IAED,OAAO,CAAC,MAAM,CAAC,WAAW;WAWZ,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY;CAarD"}
1
+ {"version":3,"file":"BackendErrorMapper.d.ts","sourceRoot":"","sources":["../../src/http/BackendErrorMapper.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,IAAI,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAgB5D,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,IAAI,CAAC;AAEnD,KAAK,qBAAqB,GAAG,YAAY,GAAG;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAC,CAAC;AACvE,KAAK,YAAY,GAAG,CAAC,CAAC,EAAE,qBAAqB,KAAK,YAAY,CAAC;AAG/D,KAAK,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,CAAC;AAE/E,KAAK,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAMhF,qBAAa,kBAAkB;IAC7B;;OAEG;IACH,OAAc,eAAe,EAAE,oBAAoB,CAuCjD;IAEF;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAsCnC;IAEF,OAAO,CAAC,MAAM,CAAC,WAAW;WAWZ,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY;CAqBrD"}
@@ -19,66 +19,70 @@
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.BackendErrorMapper = void 0;
22
+ const http_status_codes_1 = require("http-status-codes");
22
23
  const auth_1 = require("../auth/");
23
24
  const conversation_1 = require("../conversation/");
24
25
  const team_1 = require("../team/");
25
26
  const user_1 = require("../user/");
26
27
  const _1 = require("./");
27
28
  class BackendErrorMapper {
28
- static get ERRORS() {
29
- return {
30
- [_1.StatusCode.BAD_REQUEST]: {
31
- [_1.BackendErrorLabel.CLIENT_ERROR]: {
32
- 'Error in $: Failed reading: satisfy': new _1.BackendError('Wrong set of parameters.'),
33
- "[path] 'cnv' invalid: Failed reading: Invalid UUID": new conversation_1.ConversationIsUnknownError('Conversation ID is unknown.'),
34
- "[path] 'usr' invalid: Failed reading: Invalid UUID": new user_1.UserIsUnknownError('User ID is unknown.'),
35
- },
36
- [_1.BackendErrorLabel.INVALID_INVITATION_CODE]: {
37
- 'Invalid invitation code.': new team_1.InvalidInvitationCodeError('Invalid invitation code.'),
38
- },
29
+ /**
30
+ * Baseline/default handler for each (code, label). Used when no message variant matches.
31
+ */
32
+ static defaultHandlers = {
33
+ [http_status_codes_1.StatusCodes.BAD_REQUEST]: {
34
+ [_1.BackendErrorLabel.CLIENT_ERROR]: e => new _1.BackendError('Wrong set of parameters.', e.label, e.code),
35
+ [_1.BackendErrorLabel.INVALID_INVITATION_CODE]: e => new team_1.InvalidInvitationCodeError('Invalid invitation code.', e.label, e.code),
36
+ },
37
+ [http_status_codes_1.StatusCodes.FORBIDDEN]: {
38
+ [_1.BackendErrorLabel.INVALID_CREDENTIALS]: e =>
39
+ // default to logout-safe type for unknown messages
40
+ new auth_1.InvalidTokenError('Authentication failed because the token is invalid.', e.label, e.code),
41
+ [_1.BackendErrorLabel.CLIENT_ERROR]: e => new _1.BackendError('Operation not permitted.', e.label, e.code),
42
+ [_1.BackendErrorLabel.NOT_CONNECTED]: e => new user_1.UnconnectedUserError('Users are not connected.', e.label, e.code),
43
+ [_1.BackendErrorLabel.INVALID_OPERATION]: e => new conversation_1.ConversationOperationError('Cannot perform this operation.', e.label, e.code),
44
+ [_1.BackendErrorLabel.SUSPENDED_ACCOUNT]: e => new auth_1.SuspendedAccountError('Account suspended.', e.label, e.code),
45
+ },
46
+ [http_status_codes_1.StatusCodes.TOO_MANY_REQUESTS]: {
47
+ [_1.BackendErrorLabel.CLIENT_ERROR]: e => new auth_1.LoginTooFrequentError('Logins too frequent. User login temporarily disabled.', e.label, e.code),
48
+ },
49
+ [http_status_codes_1.StatusCodes.CONFLICT]: {
50
+ [_1.BackendErrorLabel.INVITE_EMAIL_EXISTS]: e => new team_1.InviteEmailInUseError('The given e-mail address is in use.', e.label, e.code),
51
+ [_1.BackendErrorLabel.KEY_EXISTS]: e => new auth_1.IdentifierExistsError('The given e-mail address is in use.', e.label, e.code),
52
+ },
53
+ [http_status_codes_1.StatusCodes.NOT_FOUND]: {
54
+ [_1.BackendErrorLabel.NOT_FOUND]: e => new team_1.ServiceNotFoundError('Service not found', e.label, e.code),
55
+ },
56
+ };
57
+ /**
58
+ * Message-specific variants for known texts under a given (code,label).
59
+ * Provides finer granularity when wording matches; otherwise we fall back to defaultHandlers.
60
+ */
61
+ static messageVariantHandlers = {
62
+ [http_status_codes_1.StatusCodes.BAD_REQUEST]: {
63
+ [_1.BackendErrorLabel.CLIENT_ERROR]: {
64
+ 'Error in $: Failed reading: satisfy': e => new _1.BackendError('Wrong set of parameters.', e.label, e.code),
65
+ "[path] 'cnv' invalid: Failed reading: Invalid UUID": e => new conversation_1.ConversationIsUnknownError('Conversation ID is unknown.', e.label, e.code),
66
+ "[path] 'usr' invalid: Failed reading: Invalid UUID": e => new user_1.UserIsUnknownError('User ID is unknown.', e.label, e.code),
39
67
  },
40
- [_1.StatusCode.FORBIDDEN]: {
41
- [_1.BackendErrorLabel.INVALID_CREDENTIALS]: {
42
- 'Invalid zauth token': new auth_1.InvalidTokenError('Authentication failed because the token is invalid.'),
43
- 'Authentication failed.': new auth_1.InvalidCredentialsError('Authentication failed because of invalid credentials.'),
44
- 'Invalid token': new auth_1.InvalidTokenError('Authentication failed because the token is invalid.'),
45
- 'Missing cookie': new auth_1.MissingCookieError('Authentication failed because the cookie is missing.'),
46
- 'Token expired': new auth_1.TokenExpiredError('Authentication failed because the token is expired.'),
47
- 'Missing cookie and token': new auth_1.MissingCookieAndTokenError('Authentication failed because the cookie and token is missing.'),
48
- },
49
- [_1.BackendErrorLabel.CLIENT_ERROR]: {
50
- 'Failed reading: Invalid zauth token': new auth_1.InvalidTokenError('Authentication failed because the token is invalid.'),
51
- },
52
- [_1.BackendErrorLabel.NOT_CONNECTED]: {
53
- 'Users are not connected': new user_1.UnconnectedUserError('Users are not connected.'),
54
- },
55
- [_1.BackendErrorLabel.INVALID_OPERATION]: {
56
- 'invalid operation for 1:1 conversations': new conversation_1.ConversationOperationError('Cannot leave 1:1 conversation.'),
57
- },
58
- [_1.BackendErrorLabel.SUSPENDED_ACCOUNT]: {
59
- 'Account suspended.': new auth_1.SuspendedAccountError('Account suspended.'),
60
- },
68
+ },
69
+ [http_status_codes_1.StatusCodes.FORBIDDEN]: {
70
+ [_1.BackendErrorLabel.INVALID_CREDENTIALS]: {
71
+ 'Invalid zauth token': e => new auth_1.InvalidTokenError('Authentication failed because the token is invalid.', e.label, e.code),
72
+ 'Invalid token': e => new auth_1.InvalidTokenError('Authentication failed because the token is invalid.', e.label, e.code),
73
+ 'Authentication failed.': e => new auth_1.InvalidCredentialsError('Authentication failed because of invalid credentials.', e.label, e.code),
74
+ 'Missing cookie': e => new auth_1.MissingCookieError('Authentication failed because the cookie is missing.', e.label, e.code),
75
+ 'Token expired': e => new auth_1.TokenExpiredError('Authentication failed because the token is expired.', e.label, e.code),
76
+ 'Missing cookie and token': e => new auth_1.MissingCookieAndTokenError('Authentication failed because both cookie and token are missing.', e.label, e.code),
61
77
  },
62
- [_1.StatusCode.TOO_MANY_REQUESTS]: {
63
- [_1.BackendErrorLabel.CLIENT_ERROR]: {
64
- 'Logins too frequent': new auth_1.LoginTooFrequentError('Logins too frequent. User login temporarily disabled.'),
65
- },
78
+ [_1.BackendErrorLabel.INVALID_OPERATION]: {
79
+ 'invalid operation for 1:1 conversations': e => new conversation_1.ConversationOperationError('Cannot leave 1:1 conversation.', e.label, e.code),
66
80
  },
67
- [_1.StatusCode.CONFLICT]: {
68
- [_1.BackendErrorLabel.INVITE_EMAIL_EXISTS]: {
69
- 'The given e-mail address is in use.': new team_1.InviteEmailInUseError('The given e-mail address is in use.'),
70
- },
71
- [_1.BackendErrorLabel.KEY_EXISTS]: {
72
- 'The given e-mail address is in use.': new auth_1.IdentifierExistsError('The given e-mail address is in use.'),
73
- },
81
+ [_1.BackendErrorLabel.CLIENT_ERROR]: {
82
+ 'Failed reading: Invalid zauth token': e => new auth_1.InvalidTokenError('Authentication failed because the token is invalid.', e.label, e.code),
74
83
  },
75
- [_1.StatusCode.NOT_FOUND]: {
76
- [_1.BackendErrorLabel.NOT_FOUND]: {
77
- 'Service not found': new team_1.ServiceNotFoundError('Service not found'),
78
- },
79
- },
80
- };
81
- }
84
+ },
85
+ };
82
86
  static logUnmapped(error, reason) {
83
87
  if (process.env.NODE_ENV === 'development') {
84
88
  console.warn('[BackendErrorMapper] Unmapped error:', {
@@ -90,16 +94,21 @@ class BackendErrorMapper {
90
94
  }
91
95
  }
92
96
  static map(error) {
93
- try {
94
- const mappedError = BackendErrorMapper.ERRORS[Number(error.code)][error.label][error.message];
95
- if (mappedError) {
96
- return mappedError;
97
- }
98
- this.logUnmapped(error, 'No matching entry found in error mapping');
97
+ const code = Number(error.code);
98
+ const label = error.label;
99
+ const message = error.message ?? '';
100
+ // 1) Message-specific variant
101
+ const messageVariantHandler = BackendErrorMapper.messageVariantHandlers[code]?.[label]?.[message];
102
+ if (messageVariantHandler) {
103
+ return messageVariantHandler(error);
99
104
  }
100
- catch (mappingError) {
101
- this.logUnmapped(error, 'Error mapping lookup failed with exception');
105
+ // 2) Default fallback for this (code,label)
106
+ const fallbackHandler = BackendErrorMapper.defaultHandlers[code]?.[label];
107
+ if (fallbackHandler) {
108
+ return fallbackHandler(error);
102
109
  }
110
+ // 3) Unknown (code,label) — keep original but log in dev
111
+ this.logUnmapped(error, 'No mapping for code+label (+message)');
103
112
  return error;
104
113
  }
105
114
  }
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@aws-sdk/client-s3": "3.873.0",
17
- "@aws-sdk/lib-storage": "3.879.0",
17
+ "@aws-sdk/lib-storage": "3.883.0",
18
18
  "@wireapp/commons": "^5.4.4",
19
19
  "@wireapp/priority-queue": "^2.1.11",
20
20
  "@wireapp/protocol-messaging": "1.53.0",
@@ -46,7 +46,7 @@
46
46
  "browser-sync": "3.0.4",
47
47
  "concurrently": "9.2.1",
48
48
  "cross-env": "10.0.0",
49
- "dotenv": "17.2.1",
49
+ "dotenv": "17.2.2",
50
50
  "jest": "^29.2.1",
51
51
  "nock": "14.0.10",
52
52
  "react": "18.3.1",
@@ -70,6 +70,6 @@
70
70
  "watch": "webpack serve --config webpack.browser.js",
71
71
  "prepare": "yarn dist"
72
72
  },
73
- "version": "27.75.4",
74
- "gitHead": "4254684c7a4ca5213619de378918ffee3a1b4409"
73
+ "version": "27.75.6",
74
+ "gitHead": "8b55a99d27eb07e9757568c25e4a4bfe6c11b380"
75
75
  }