|
| 1 | +/* |
| 2 | +Copyright 2021 Adobe. All rights reserved. |
| 3 | +This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | +of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +Unless required by applicable law or agreed to in writing, software distributed under |
| 7 | +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 8 | +OF ANY KIND, either express or implied. See the License for the specific language |
| 9 | +governing permissions and limitations under the License. |
| 10 | +*/ |
| 11 | + |
| 12 | +const { ErrorWrapper, createUpdater } = require('@adobe/aio-lib-core-errors').AioCoreSDKErrorWrapper |
| 13 | + |
| 14 | +const codes = {} |
| 15 | +const messages = new Map() |
| 16 | + |
| 17 | +/** |
| 18 | + * Create an Updater for the Error wrapper |
| 19 | + * |
| 20 | + * @ignore |
| 21 | + */ |
| 22 | +const Updater = createUpdater( |
| 23 | + // object that stores the error classes (to be exported) |
| 24 | + codes, |
| 25 | + // Map that stores the error strings (to be exported) |
| 26 | + messages, |
| 27 | +) |
| 28 | + |
| 29 | +/** |
| 30 | + * Provides a wrapper to easily create classes of a certain name, and values |
| 31 | + * |
| 32 | + * @ignore |
| 33 | + */ |
| 34 | +const E = ErrorWrapper( |
| 35 | + // The class name for your SDK Error. Your Error objects will be these objects |
| 36 | + 'CloudManagerCLIConfigurationError', |
| 37 | + // The name of your SDK. This will be a property in your Error objects |
| 38 | + 'CloudManagerCLI', |
| 39 | + // the object returned from the CreateUpdater call above |
| 40 | + Updater, |
| 41 | + // the base class that your Error class is extending. AioCoreSDKError is the default |
| 42 | + /* AioCoreSDKError, */ |
| 43 | +) |
| 44 | + |
| 45 | +module.exports = { |
| 46 | + codes, |
| 47 | + messages, |
| 48 | +} |
| 49 | + |
| 50 | +// Define your error codes with the wrapper |
| 51 | +E('CLI_ONLY_COMMAND', 'This command is only intended to be used with a user token, not a service account. The org id for a service account must be provided in the service account configuration.') |
| 52 | +E('NO_CM_ORGS', 'No Cloud Manager authorized organizations found.') |
| 53 | +E('NO_IMS_CONTEXT', 'Unable to find IMS context %s.') |
| 54 | +E('CLI_AUTH_NO_ORG', 'The CLI has been authenticated, but no organization has been selected. To select an organization, run "aio cloudmanager:org:select". Alternatively, define the IMS context configuration %s with a service account.') |
| 55 | +E('NO_DEFAULT_IMS_CONTEXT', 'There is no IMS context configuration defined for %s. Either define this context configuration or authenticate using "aio auth:login" and select an organization using "aio cloudmanager:org:select".') |
| 56 | +E('IMS_CONTEXT_MISSING_FIELDS', 'One or more of the required fields in %s were not set. Missing keys were %s.') |
| 57 | +E('IMS_CONTEXT_MISSING_METASCOPE', 'The configuration %s is missing the required metascope %s.') |
| 58 | +E('CLI_AUTH_EXPLICIT_NO_AUTH', 'cli context explicitly enabled, but not authenticated. You must run "aio auth:login" first.') |
| 59 | +E('CLI_AUTH_EXPLICIT_NO_ORG', 'cli context explicitly enabled but no org id specified. Configure using either "cloudmanager_orgid" or by running "aio cloudmanager:org:select"') |
0 commit comments