From 58909ca78e0b846de2d5cbaefa0168acbc56b9f3 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Tue, 8 Feb 2022 10:23:59 +0100 Subject: [PATCH] refactor: this unsupported() function was elevated to some undeserved special privilege (#127) Co-authored-by: James Gregory --- src/errors.ts | 15 --------------- src/server/server.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index 9a9b6db1..8df93bc6 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,6 +1,3 @@ -import { Response } from "express"; -import { LogService } from "./services/LogService"; - export class UnsupportedError extends Error {} export class CognitoError extends Error { @@ -83,15 +80,3 @@ export class InvalidParameterError extends CognitoError { super("InvalidParameterException", message); } } - -export const unsupported = ( - message: string, - res: Response, - logger: LogService -) => { - logger.error(`Cognito Local unsupported feature: ${message}`); - return res.status(500).json({ - code: "CognitoLocal#Unsupported", - message: `Cognito Local unsupported feature: ${message}`, - }); -}; diff --git a/src/server/server.ts b/src/server/server.ts index 03ca8789..73c3d0fb 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -4,7 +4,7 @@ import express from "express"; import * as http from "http"; import type { Logger } from "pino"; import * as uuid from "uuid"; -import { CognitoError, unsupported, UnsupportedError } from "../errors"; +import { CognitoError, UnsupportedError } from "../errors"; import { Router } from "../targets/router"; import PublicKey from "../keys/cognitoLocal.public.json"; import Pino from "pino-http"; @@ -105,7 +105,11 @@ export const createServer = ( req.log.info("======"); } - unsupported(ex.message, res, req.log); + req.log.error(`Cognito Local unsupported feature: ${ex.message}`); + res.status(500).json({ + code: "CognitoLocal#Unsupported", + message: `Cognito Local unsupported feature: ${ex.message}`, + }); return; } else if (ex instanceof CognitoError) { req.log.warn(ex, `Error handling target: ${target}`);