Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/micro 287 configurable error behaviour on registration #254

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading