Total Complexity | 9 |
Complexity/F | 1.29 |
Lines of Code | 43 |
Function Count | 7 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export default class ExtensionErrorService { |
||
2 | static get name() { |
||
3 | return 'extensionErrorService'; |
||
4 | } |
||
5 | |||
6 | constructor(errorCodes, fallbackError) { |
||
7 | this.errorCodes = errorCodes; |
||
8 | this.fallbackError = fallbackError; |
||
9 | } |
||
10 | |||
11 | handleErrorResponse(errorResponse, translator) { |
||
12 | const errors = Shopware.Utils.get(errorResponse, 'response.data.errors', []); |
||
|
|||
13 | |||
14 | if (!Array.isArray(errors)) { |
||
15 | return []; |
||
16 | } |
||
17 | |||
18 | return errors.map((error) => { |
||
19 | return this.handleError(error, translator); |
||
20 | }); |
||
21 | } |
||
22 | |||
23 | handleError(error, translator) { |
||
24 | return this._translateRawNotification( |
||
25 | this._getNotification(error, translator), |
||
26 | translator |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | _getNotification(error) { |
||
31 | return this.errorCodes[error.code] ? |
||
32 | this.errorCodes[error.code] : |
||
33 | this.fallbackError; |
||
34 | } |
||
35 | |||
36 | _translateRawNotification(notification, translator) { |
||
37 | return { |
||
38 | title: translator.$tc(notification.title), |
||
39 | message: translator.$tc(notification.message), |
||
40 | autoClose: notification.autoClose |
||
41 | }; |
||
42 | } |
||
43 | } |
||
44 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.