Skip to content

Commit

Permalink
refactor: this unsupported() function was elevated to some undeserved…
Browse files Browse the repository at this point in the history
… special privilege (jagregory#127)

Co-authored-by: James Gregory <[email protected]>
  • Loading branch information
christhomas and jagregory authored Feb 8, 2022
1 parent f787fab commit 58909ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Response } from "express";
import { LogService } from "./services/LogService";

export class UnsupportedError extends Error {}

export class CognitoError extends Error {
Expand Down Expand Up @@ -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}`,
});
};
8 changes: 6 additions & 2 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 58909ca

Please sign in to comment.