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:
commit
4c741588bf
1
NEWS.md
1
NEWS.md
@ -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
|
||||||
|
@ -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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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()
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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()
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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()
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user