From 16998a9e44f437aa78cac11976e8944d1361b945 Mon Sep 17 00:00:00 2001 From: Kyriakos Lesgidis <44189854+klesgidis@users.noreply.github.com> Date: Mon, 17 Jan 2022 14:53:45 +0200 Subject: [PATCH] Move errors & export them (#278) --- src/{middlewares => }/errors/axios-error.ts | 0 src/{middlewares => }/errors/custom-error.ts | 0 src/errors/index.ts | 3 +++ src/{middlewares => }/errors/validation-error.ts | 0 src/helpers/interceptors/axios-error-interceptor.ts | 2 +- src/index.ts | 3 ++- src/initializers/log4js/json-appender.ts | 2 +- src/middlewares/validate-params.ts | 2 +- test/{initializers/koa => }/errors/axios-errors.test.ts | 2 +- test/{initializers/koa => }/errors/custom-error.test.ts | 2 +- test/{initializers/koa => }/errors/validation-error.test.ts | 2 +- 11 files changed, 11 insertions(+), 7 deletions(-) rename src/{middlewares => }/errors/axios-error.ts (100%) rename src/{middlewares => }/errors/custom-error.ts (100%) create mode 100644 src/errors/index.ts rename src/{middlewares => }/errors/validation-error.ts (100%) rename test/{initializers/koa => }/errors/axios-errors.test.ts (90%) rename test/{initializers/koa => }/errors/custom-error.test.ts (88%) rename test/{initializers/koa => }/errors/validation-error.test.ts (89%) diff --git a/src/middlewares/errors/axios-error.ts b/src/errors/axios-error.ts similarity index 100% rename from src/middlewares/errors/axios-error.ts rename to src/errors/axios-error.ts diff --git a/src/middlewares/errors/custom-error.ts b/src/errors/custom-error.ts similarity index 100% rename from src/middlewares/errors/custom-error.ts rename to src/errors/custom-error.ts diff --git a/src/errors/index.ts b/src/errors/index.ts new file mode 100644 index 00000000..59f6d792 --- /dev/null +++ b/src/errors/index.ts @@ -0,0 +1,3 @@ +export { AxiosError } from './axios-error'; +export { CustomError } from './custom-error'; +export { ValidationError } from './validation-error'; diff --git a/src/middlewares/errors/validation-error.ts b/src/errors/validation-error.ts similarity index 100% rename from src/middlewares/errors/validation-error.ts rename to src/errors/validation-error.ts diff --git a/src/helpers/interceptors/axios-error-interceptor.ts b/src/helpers/interceptors/axios-error-interceptor.ts index 880902be..48cc37f1 100644 --- a/src/helpers/interceptors/axios-error-interceptor.ts +++ b/src/helpers/interceptors/axios-error-interceptor.ts @@ -1,5 +1,5 @@ import requireInjected from '../../require-injected'; -import { AxiosError } from '../../middlewares/errors/axios-error'; +import { AxiosError } from '../../errors/axios-error'; export default () => { const axios = requireInjected('axios'); diff --git a/src/index.ts b/src/index.ts index 0ab9b924..0aa9b75d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import Orka from './orka'; import * as middlewares from './middlewares'; import * as helpers from './helpers'; +import * as errors from './errors'; export { default as builder, getRequestContext, runWithContext } from './builder'; export { getLogger } from './initializers/log4js'; @@ -14,4 +15,4 @@ export { getRedis, createRedisConnection } from './initializers/redis'; export { getBull } from './initializers/bull'; export { getPrometheus } from './initializers/prometheus'; export { getPostgresPool, withPostgresTransaction } from './initializers/postgres'; -export { middlewares, helpers }; +export { middlewares, helpers, errors }; diff --git a/src/initializers/log4js/json-appender.ts b/src/initializers/log4js/json-appender.ts index 47444c76..cdf9a142 100644 --- a/src/initializers/log4js/json-appender.ts +++ b/src/initializers/log4js/json-appender.ts @@ -58,7 +58,7 @@ export const createValidLog = (layout, logEvent, config) => { timestamp: logEvent.startTime, severity: logEvent.level.levelStr, categoryName: logEvent.categoryName, - message, + message: message, context }; }; diff --git a/src/middlewares/validate-params.ts b/src/middlewares/validate-params.ts index 15c03de0..ee657fee 100644 --- a/src/middlewares/validate-params.ts +++ b/src/middlewares/validate-params.ts @@ -1,5 +1,5 @@ import * as Joi from '@hapi/joi'; -import { ValidationError } from './errors/validation-error'; +import { ValidationError } from '../errors/validation-error'; import * as Koa from 'koa'; function validate(body: any, schema: Joi.ObjectSchema) { diff --git a/test/initializers/koa/errors/axios-errors.test.ts b/test/errors/axios-errors.test.ts similarity index 90% rename from test/initializers/koa/errors/axios-errors.test.ts rename to test/errors/axios-errors.test.ts index 07f2db57..1ee7f596 100644 --- a/test/initializers/koa/errors/axios-errors.test.ts +++ b/test/errors/axios-errors.test.ts @@ -1,7 +1,7 @@ import * as _axios from 'axios'; import snapshot = require('snap-shot-it'); import * as util from 'util'; -import { AxiosError } from '../../../../src/middlewares/errors/axios-error'; +import { AxiosError } from '../../src/errors/axios-error'; import * as sinon from 'sinon'; const sandbox = sinon.createSandbox(); diff --git a/test/initializers/koa/errors/custom-error.test.ts b/test/errors/custom-error.test.ts similarity index 88% rename from test/initializers/koa/errors/custom-error.test.ts rename to test/errors/custom-error.test.ts index 2486d470..68189859 100644 --- a/test/initializers/koa/errors/custom-error.test.ts +++ b/test/errors/custom-error.test.ts @@ -1,6 +1,6 @@ import 'should'; import * as sinon from 'sinon'; -import { CustomError } from '../../../../src/middlewares/errors/custom-error'; +import { CustomError } from '../../src/errors/custom-error'; const sandbox = sinon.createSandbox(); diff --git a/test/initializers/koa/errors/validation-error.test.ts b/test/errors/validation-error.test.ts similarity index 89% rename from test/initializers/koa/errors/validation-error.test.ts rename to test/errors/validation-error.test.ts index fde54b5f..80fcd832 100644 --- a/test/initializers/koa/errors/validation-error.test.ts +++ b/test/errors/validation-error.test.ts @@ -1,6 +1,6 @@ import 'should'; import * as sinon from 'sinon'; -import { ValidationError } from '../../../../src/middlewares/errors/validation-error'; +import { ValidationError } from '../../src/errors/validation-error'; const sandbox = sinon.createSandbox();