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.
- 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.
- Attach error middleware to api router instead of for each controller.
## 4.0.0
Released 2019-09-30

View File

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

View File

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

View File

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

View File

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