Skip to content

Commit

Permalink
Merge pull request #254 from aligent/feature/MICRO-287_configurable-e…
Browse files Browse the repository at this point in the history
…rror-behaviour-on-registration

Feature/micro 287 configurable error behaviour on registration
  • Loading branch information
tvhees authored Feb 9, 2024
2 parents 1a11246 + 740c5f4 commit cc06b96
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Microservices registered with the [magento2-microservice-config](https://bitbuck

## Admin Interface

The admin interface is provided as a link to an externally hosed web application which is rendered in the Magento admin interface as an `iframe`. Authorisation context will be injected into the iframe when loaded.
The admin interface is provided as a link to an externally hosted web application which is rendered in the Magento admin interface as an `iframe`. Authorisation context will be injected into the iframe when loaded.

## Deployment

Expand All @@ -32,11 +32,12 @@ custom:
### Variables
| Variable | Usage |
| --------------------- | ------------------------------------------------------------------------------------------------------ |
| magentoUrl | The base URL - including scheme - of the Magento instance. |
| magentoApiToken | The api token for registering with Magento instance. |
| displayName | The name of the application/service. |
| description | Short description about the application/service. If not provided, `resources/Description` will be used |
| permission | Array of Magento permission. Webapp does not need this |
| domainOutputKeyPrefix | The prefix of webapp domain output key. The default value is `landingDomain`. |
| Variable | Type | Usage |
| --------------------- | ------- | --------------------------------------------------------------------------------------------------------------- |
| magentoUrl | string | The base URL - including scheme - of the Magento instance. |
| magentoApiToken | string | The api token for registering with Magento instance. |
| displayName | string | The name of the application/service. |
| description | string | Short description about the application/service. If not provided, `resources/Description` will be used |
| permission | string | Array of Magento permission. Webapp does not need this. |
| domainOutputKeyPrefix | string | The prefix of webapp domain output key. The default value is `landingDomain`. |
| errorOnFailure | boolean | Whether the plugin should throw an error when a call to the Magento instance fails. The default value is `true` |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aligent/serverless-magento",
"version": "0.0.8",
"version": "0.1.0",
"description": "A Serverless framework plugin for handling registration with the aligent/magento2-microservice-config module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface ServiceRegistration {
description?: string;
permissions?: string[];
domainOutputKeyPrefix: string;
errorOnFailure?: boolean;
}

type ServerlessResources = Service['resources'] & {
Expand Down Expand Up @@ -76,6 +77,7 @@ class ServerlessMagento implements ServerlessPlugin {
items: { type: 'string' },
},
domainOutputKeyPrefix: { type: 'string' },
errorOnFailure: { type: 'boolean' },
},
required: ['magentoUrl', 'magentoApiToken', 'displayName'],
},
Expand All @@ -91,6 +93,7 @@ class ServerlessMagento implements ServerlessPlugin {

private async initialize() {
this.serviceRegistration = {
errorOnFailure: true, // Default to throw an error when failing to register/deregister
...this.service.custom.serviceRegistration,
domainOutputKeyPrefix:
this.service.custom.serviceRegistration.domainOutputKeyPrefix ||
Expand Down Expand Up @@ -155,7 +158,11 @@ class ServerlessMagento implements ServerlessPlugin {
)}`;
}

throw new this.serverless.classes.Error(errorMessage);
if (this.serviceRegistration.errorOnFailure) {
throw new this.serverless.classes.Error(errorMessage);
} else {
this.log.warning(errorMessage);
}
}
}

Expand Down Expand Up @@ -186,7 +193,11 @@ class ServerlessMagento implements ServerlessPlugin {
)}`;
}

throw new this.serverless.classes.Error(errorMessage);
if (this.serviceRegistration.errorOnFailure) {
throw new this.serverless.classes.Error(errorMessage);
} else {
this.log.warning(errorMessage);
}
}
}

Expand Down

0 comments on commit cc06b96

Please sign in to comment.