refactor: unify plugin conflict errors

Closes #58
This commit is contained in:
Jovan Krunić
2019-05-17 14:14:27 +02:00
parent 3f10129356
commit e3ea846470
2 changed files with 16 additions and 26 deletions

View File

@@ -13,6 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {ValidationError} from 'jsonschema'; import {ValidationError} from 'jsonschema';
import {SCPluginMetaData} from '../routes/plugin/PluginRegisterRequest';
/** /**
* A generic error that can be returned by the backend if somethings fails during the processing of a request * A generic error that can be returned by the backend if somethings fails during the processing of a request
@@ -169,13 +170,23 @@ export class SCParametersNotAcceptable extends SCError {
*/ */
export class SCPluginAlreadyRegisteredErrorResponse extends SCError { export class SCPluginAlreadyRegisteredErrorResponse extends SCError {
/** /**
* Create a PluginAlreadyRegisteredError * Meta data of a registered plugin, which is in a conflict with the plugin we want to register.
* If the stack is disabled this is not set for security reasons
*/
additionalData?: SCPluginMetaData;
/**
* Create a SCPluginAlreadyRegisteredError
* *
* @param message contains potential differences in other parameters outside of the name * @param message Provide further information why an already registered plugin matches the one we want to register
* @param plugin Provides meta data of a registered plugin, which is in a conflict with the plugin we want to register
* @param stack Set to true if a stack trace should be created * @param stack Set to true if a stack trace should be created
*/ */
constructor(message: string, stack?: boolean) { constructor(message: string, plugin: SCPluginMetaData, stack?: boolean) {
super('PluginRegisteringFailedError', message, 409, stack); super('SCPluginAlreadyRegisteredError', message, 409, stack);
if (stack) {
this.additionalData = plugin;
}
} }
} }
@@ -194,25 +205,6 @@ export class SCPluginRegisteringFailedErrorResponse extends SCError {
} }
} }
/**
* An error that is returned whenever there is a plugin request that is supposed to register a route, that is already
* registered
* This usually indicates that two **different** plugins use the same route.
*/
export class SCPluginRouteAlreadyRegisteredErrorResponse extends SCError {
/**
* Create a PluginRouteAlreadyRegisteredError
*
* @param registeredName The name by the plugin that has already registered the route previously
* @param registeredUrl The URL by the plugin that has already registered the route previously
* @param stack Set to true if a stack trace should be created
*/
constructor(registeredName: string, registeredUrl: string, stack?: boolean) {
super('PluginRouteAlreadyRegisteredError',
`Already registered by "${registeredName}" under URL "${registeredUrl}".`, 409, stack);
}
}
/** /**
* An error that is returned whenever there is a syntax error * An error that is returned whenever there is a syntax error
*/ */

View File

@@ -19,7 +19,6 @@ import {
SCMethodNotAllowedErrorResponse, SCParametersNotAcceptable, SCMethodNotAllowedErrorResponse, SCParametersNotAcceptable,
SCPluginAlreadyRegisteredErrorResponse, SCPluginAlreadyRegisteredErrorResponse,
SCPluginRegisteringFailedErrorResponse, SCPluginRegisteringFailedErrorResponse,
SCPluginRouteAlreadyRegisteredErrorResponse,
SCRequestBodyTooLargeErrorResponse, SCRequestBodyTooLargeErrorResponse,
SCSyntaxErrorResponse, SCSyntaxErrorResponse,
} from '../../errors/ErrorResponse'; } from '../../errors/ErrorResponse';
@@ -103,7 +102,6 @@ export class SCPluginRegisterRoute extends SCAbstractRoute {
SCParametersNotAcceptable, SCParametersNotAcceptable,
SCPluginAlreadyRegisteredErrorResponse, SCPluginAlreadyRegisteredErrorResponse,
SCPluginRegisteringFailedErrorResponse, SCPluginRegisteringFailedErrorResponse,
SCPluginRouteAlreadyRegisteredErrorResponse,
SCRequestBodyTooLargeErrorResponse, SCRequestBodyTooLargeErrorResponse,
SCSyntaxErrorResponse, SCSyntaxErrorResponse,
]; ];