From 672995423891f5e5e22a24704f52ccb9d6018257 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Mon, 18 Nov 2019 17:47:43 +0100 Subject: [PATCH 1/4] chore(deps): update to mapper library with default mapping strategy --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b3f14f5..2fc9360 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ }, "dependencies": { "http-problem-details": "^0.1.2", - "http-problem-details-mapper": "^0.1.3" + "http-problem-details-mapper": "^0.1.4" }, "husky": { "hooks": { diff --git a/yarn.lock b/yarn.lock index ca1a3fc..dbfe429 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1416,10 +1416,10 @@ hosted-git-info@^2.1.4: resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" integrity sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w== -http-problem-details-mapper@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/http-problem-details-mapper/-/http-problem-details-mapper-0.1.3.tgz#4901e550d3081fb713b67157300b83ad41dc230d" - integrity sha512-Ps/DNwhH4cM6Sneh5Qg7ud+lTAsMmQuFDdMAKWwd7lx6pGPNh8A3c9T9O2BktN2J4mXk41zfTpMe1bMiItUviQ== +http-problem-details-mapper@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/http-problem-details-mapper/-/http-problem-details-mapper-0.1.4.tgz#c231858e3e3a1e9521a2750b82114e83cbe61ae9" + integrity sha512-gvNuKvQzJvAoN6QklhgZD70YpuQujNA+9zLUKV7Kj8ha04HMfp9TbBVyw3GA8kc9xaNcwx6/BTZevKTemzGikQ== http-problem-details@^0.1.2: version "0.1.4" From 811947a774f9a749299058500e3c0364feaf8d8d Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Mon, 18 Nov 2019 17:57:01 +0100 Subject: [PATCH 2/4] refactor: remove express mapping strategy and tests BREAKING CHANGE: `DefaultMappingStrategy` from `http-problem-details-mapper` or your own implementation of `IMappingStrategy` / `MappingStrategy` has to be used now. --- src/ExpressMappingStrategy.ts | 20 -------------------- src/index.ts | 2 -- test/ExpressMappingStrategyTests.ts | 15 --------------- 3 files changed, 37 deletions(-) delete mode 100644 src/ExpressMappingStrategy.ts delete mode 100644 test/ExpressMappingStrategyTests.ts diff --git a/src/ExpressMappingStrategy.ts b/src/ExpressMappingStrategy.ts deleted file mode 100644 index 844b0f0..0000000 --- a/src/ExpressMappingStrategy.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { IMappingStrategy, MapperRegistry } from 'http-problem-details-mapper' -import { ProblemDocument } from 'http-problem-details' - -export class ExpressMappingStrategy implements IMappingStrategy { - public registry: MapperRegistry; - - public constructor (registry: MapperRegistry) { - this.registry = registry - } - - public map (error: any): ProblemDocument | null { - const err = error - const errorMapper = this.registry.getMapper(error) - if (errorMapper) { - return errorMapper.mapError(err) - } - - return null - } -} diff --git a/src/index.ts b/src/index.ts index d546913..3922c83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ -import { ExpressMappingStrategy } from './ExpressMappingStrategy' import { HttpProblemResponse } from './HttpProblemResponse' export { - ExpressMappingStrategy, HttpProblemResponse } diff --git a/test/ExpressMappingStrategyTests.ts b/test/ExpressMappingStrategyTests.ts deleted file mode 100644 index 694d067..0000000 --- a/test/ExpressMappingStrategyTests.ts +++ /dev/null @@ -1,15 +0,0 @@ -import 'should' -import { ExpressMappingStrategy } from '../src' -import { MapperRegistry } from 'http-problem-details-mapper' - -describe('ExpressMappingStrategy', (): void => { - describe('When mapping', (): void => { - it('should return status code 500 problem', function (done): void { - const strategy = new ExpressMappingStrategy(new MapperRegistry()) - const problem = strategy.map(new Error())! - problem.should.have.property('type', 'about:blank') - problem.status.should.equal(500) - return done() - }) - }) -}) From 1d0645433fe4d574280c0eda5ab171a59c73a306 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Mon, 18 Nov 2019 21:28:44 +0100 Subject: [PATCH 3/4] docs: replace express mapping strategy by default mapping strategy --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c98ad2f..ad466d0 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,10 @@ Notice that the `HttpProblemResponse` must come last. A global error logger woul precede it and forward the error to the `next` function. ```js -import { ExpressMappingStrategy, HttpProblemResponse } from 'express-http-problem-details' -import { MapperRegistry } from 'http-problem-details-mapper' +import { HttpProblemResponse } from 'express-http-problem-details' +import { DefaultMappingStrategy, MapperRegistry } from 'http-problem-details-mapper' -const strategy = new ExpressMappingStrategy( +const strategy = new DefaultMappingStrategy( new MapperRegistry() .registerMapper(new NotFoundErrorMapper())) From de444e25c003f7d901373f565d19d5c4313143fd Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Mon, 18 Nov 2019 21:31:26 +0100 Subject: [PATCH 4/4] ci: remove tests there are no tests at the moment --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 373e807..b5b6e39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,6 +34,4 @@ jobs: - node_modules key: v1-dependencies-{{ checksum "yarn.lock" }} - # run tests! - - run: yarn test