Merge pull request #630 from CartoDB/move-up-error-mw

Attach error middleware to api router instead of for each controller
This commit is contained in:
Daniel G. Aubert 2019-11-12 13:22:07 +01:00 committed by GitHub
commit 4c741588bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 11 deletions

View File

@ -12,6 +12,7 @@ Announcements:
- Added mechanism to inject custom middlewares through configuration. - Added mechanism to inject custom middlewares through configuration.
- Stop requiring unused config properties: "base_url". - Stop requiring unused config properties: "base_url".
- Be able to set a coherent TTL in Cache-Control header to expire all resources belonging to a query simultaneously. - Be able to set a coherent TTL in Cache-Control header to expire all resources belonging to a query simultaneously.
- Attach error middleware to api router instead of for each controller.
## 4.0.0 ## 4.0.0
Released 2019-09-30 Released 2019-09-30

View File

@ -7,6 +7,7 @@ const SqlRouter = require('./sql/sql-router');
const HealthCheckController = require('./health-check-controller'); const HealthCheckController = require('./health-check-controller');
const VersionController = require('./version-controller'); const VersionController = require('./version-controller');
const JobsWipController = require('./jobs-wip-controller'); const JobsWipController = require('./jobs-wip-controller');
const error = require('./middlewares/error');
const BatchLogger = require('../batch/batch-logger'); const BatchLogger = require('../batch/batch-logger');
@ -59,6 +60,8 @@ module.exports = class ApiRouter {
this.sqlRouter.route(apiRouter, route.sql); this.sqlRouter.route(apiRouter, route.sql);
paths.forEach(path => app.use(path, apiRouter)); paths.forEach(path => app.use(path, apiRouter));
apiRouter.use(error());
}); });
} }
}; };

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
const user = require('../middlewares/user'); const user = require('../middlewares/user');
const error = require('../middlewares/error');
const authorization = require('../middlewares/authorization'); const authorization = require('../middlewares/authorization');
const connectionParams = require('../middlewares/connection-params'); const connectionParams = require('../middlewares/connection-params');
const { initializeProfiler } = require('../middlewares/profiler'); const { initializeProfiler } = require('../middlewares/profiler');
@ -36,8 +35,7 @@ module.exports = class CopyController {
dbQuota(), dbQuota(),
params({ strategy: 'copyfrom' }), params({ strategy: 'copyfrom' }),
handleCopyFrom(this.logger), handleCopyFrom(this.logger),
errorHandler(this.logger), errorHandler(this.logger)
error()
]; ];
}; };
@ -51,8 +49,7 @@ module.exports = class CopyController {
connectionParams(this.userDatabaseService), connectionParams(this.userDatabaseService),
params({ strategy: 'copyto' }), params({ strategy: 'copyto' }),
handleCopyTo(this.logger), handleCopyTo(this.logger),
errorHandler(this.logger), errorHandler(this.logger)
error()
]; ];
}; };

View File

@ -7,7 +7,6 @@ const user = require('../middlewares/user');
const { initializeProfiler, finishProfiler } = require('../middlewares/profiler'); const { initializeProfiler, finishProfiler } = require('../middlewares/profiler');
const authorization = require('../middlewares/authorization'); const authorization = require('../middlewares/authorization');
const connectionParams = require('../middlewares/connection-params'); const connectionParams = require('../middlewares/connection-params');
const error = require('../middlewares/error');
const rateLimits = require('../middlewares/rate-limit'); const rateLimits = require('../middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits; const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits;
const params = require('../middlewares/params'); const params = require('../middlewares/params');
@ -67,8 +66,7 @@ function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService
logJobResult(action), logJobResult(action),
incrementSuccessMetrics(statsdClient), incrementSuccessMetrics(statsdClient),
sendResponse(), sendResponse(),
incrementErrorMetrics(statsdClient), incrementErrorMetrics(statsdClient)
error()
]; ];
}; };
} }

View File

@ -19,7 +19,6 @@ const surrogateKey = require('../middlewares/surrogate-key');
const lastModified = require('../middlewares/last-modified'); const lastModified = require('../middlewares/last-modified');
const formatter = require('../middlewares/formatter'); const formatter = require('../middlewares/formatter');
const content = require('../middlewares/content'); const content = require('../middlewares/content');
const error = require('../middlewares/error');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits; const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimits;
const PSQL = require('cartodb-psql'); const PSQL = require('cartodb-psql');
@ -56,8 +55,7 @@ module.exports = class QueryController {
lastModified(), lastModified(),
formatter(), formatter(),
content(), content(),
handleQuery({ stats: this.stats }), handleQuery({ stats: this.stats })
error()
]; ];
}; };