Merge pull request #1437 from spotify/mob/job-processor

Job Processor and Scaffolder Flow Implementation
This commit is contained in:
Ben Lambert
2020-06-29 14:33:22 +02:00
committed by GitHub
27 changed files with 745 additions and 76 deletions
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as winston from 'winston';
let rootLogger: winston.Logger = winston.createLogger({
@@ -34,6 +34,29 @@ describe('errorHandler', () => {
expect(response.text).toBe('some message');
});
it('doesnt try to send the response again if its already been sent', async () => {
const app = express();
const mockSend = jest.fn();
app.use('/works_with_async_fail', (_, res) => {
res.status(200).send('hello');
// mutate the response object to test the middlware.
// it's hard to catch errors inside middleware from the outside.
// @ts-ignore
res.send = mockSend;
throw new Error('some message');
});
app.use(errorHandler());
const response = await request(app).get('/works_with_async_fail');
expect(response.status).toBe(200);
expect(response.text).toBe('hello');
expect(mockSend).not.toHaveBeenCalled();
});
it('takes code from http-errors library errors', async () => {
const app = express();
app.use('/breaks', () => {
@@ -53,7 +53,10 @@ export function errorHandler(
next: NextFunction,
) => {
if (response.headersSent) {
// If the headers have already been sent, do not send the response again
// as this will throw an error in the backend.
next(error);
return;
}
const status = getStatusCode(error);