From e3ea846470e8c9ee6797dd662fabd2775705395a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Fri, 17 May 2019 14:14:27 +0200 Subject: [PATCH] refactor: unify plugin conflict errors Closes #58 --- src/core/protocol/errors/ErrorResponse.ts | 40 ++++++++----------- .../routes/plugin/PluginRegisterRequest.ts | 2 - 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/core/protocol/errors/ErrorResponse.ts b/src/core/protocol/errors/ErrorResponse.ts index 269c86f2..7b494847 100644 --- a/src/core/protocol/errors/ErrorResponse.ts +++ b/src/core/protocol/errors/ErrorResponse.ts @@ -13,6 +13,7 @@ * this program. If not, see . */ 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 @@ -169,13 +170,23 @@ export class SCParametersNotAcceptable 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 */ - constructor(message: string, stack?: boolean) { - super('PluginRegisteringFailedError', message, 409, stack); + constructor(message: string, plugin: SCPluginMetaData, stack?: boolean) { + 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 */ @@ -241,7 +233,7 @@ export class SCInternalServerErrorResponse extends SCError { * Create a SCInternalServerErrorResponse * * @param err Internal server error - * @param stack Set to true if a stack trace should be created + * @param stack Set to true if a stack trace should be created * and the internal server error should be displayed to the client */ constructor(err?: Error, stack?: boolean) { diff --git a/src/core/protocol/routes/plugin/PluginRegisterRequest.ts b/src/core/protocol/routes/plugin/PluginRegisterRequest.ts index 0b64fd4b..849b404f 100644 --- a/src/core/protocol/routes/plugin/PluginRegisterRequest.ts +++ b/src/core/protocol/routes/plugin/PluginRegisterRequest.ts @@ -19,7 +19,6 @@ import { SCMethodNotAllowedErrorResponse, SCParametersNotAcceptable, SCPluginAlreadyRegisteredErrorResponse, SCPluginRegisteringFailedErrorResponse, - SCPluginRouteAlreadyRegisteredErrorResponse, SCRequestBodyTooLargeErrorResponse, SCSyntaxErrorResponse, } from '../../errors/ErrorResponse'; @@ -103,7 +102,6 @@ export class SCPluginRegisterRoute extends SCAbstractRoute { SCParametersNotAcceptable, SCPluginAlreadyRegisteredErrorResponse, SCPluginRegisteringFailedErrorResponse, - SCPluginRouteAlreadyRegisteredErrorResponse, SCRequestBodyTooLargeErrorResponse, SCSyntaxErrorResponse, ];