Skip to content

Commit a227971

Browse files
committed
Genric message
1 parent 270a538 commit a227971

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

example-application/business-logic/order-service.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ const axiosRetry = require('axios-retry').default;
55
const OrderRepository = require('../data-access/order-repository');
66
const { AppError } = require('../error-handling');
77
const MessageQueueClient = require('../libraries/message-queue-client');
8+
const { AxiosError } = require('axios');
89

910
const axiosHTTPClient = axios.create({});
10-
// axiosRetry(axiosHTTPClient, {
11-
// retries: 3,
12-
// onRetry: (count, err) => console.log('On retry', count, err),
13-
// retryCondition: (request) => {
14-
// console.log('Retry condition now', request.response.status);
15-
// if (request.response.status >= 500) {
16-
// return true;
17-
// }
18-
// return false;
19-
// },
20-
// });
11+
axiosRetry(axiosHTTPClient, {
12+
retries: 3,
13+
onRetry: (count, err) => console.log('On retry', count, err),
14+
retryCondition: (request) => {
15+
console.log('Retry condition now', request.response.status);
16+
if (request.response.status >= 500) {
17+
return true;
18+
}
19+
return false;
20+
},
21+
});
2122

2223
module.exports.addOrder = async function (newOrder) {
2324
// validation

example-application/test/createOrder.callingOtherServices.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ describe('/api', () => {
118118
testSetup.removeUserNock();
119119
nock('http://localhost')
120120
.get('/user/1')
121+
.times(1)
121122
.delay(3000)
122123
.reply(200, { id: 1, name: 'John' });
123124
const orderToAdd = {

example-application/test/createOrder.observabilityCheck.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AppError, metricsExporter } from '../error-handling';
44
import logger from '../libraries/logger';
55
import { testSetup } from './setup/test-file-setup';
66

7+
let processExitStub: sinon.SinonStub;
8+
79
beforeAll(async () => {
810
await testSetup.start({
911
startAPI: true,
@@ -16,7 +18,7 @@ beforeAll(async () => {
1618

1719
beforeEach(() => {
1820
testSetup.resetBeforeEach();
19-
sinon.stub(process, 'exit');
21+
processExitStub = sinon.stub(process, 'exit');
2022
});
2123

2224
afterAll(async () => {
@@ -87,7 +89,7 @@ describe('Error Handling', () => {
8789
productId: 2,
8890
mode: 'approved',
8991
};
90-
sinon.restore();
92+
processExitStub.restore();
9193
const processExitListener = sinon.stub(process, 'exit');
9294
const errorToThrow = new AppError(
9395
'saving-failed',
@@ -111,7 +113,7 @@ describe('Error Handling', () => {
111113
productId: 2,
112114
mode: 'approved',
113115
};
114-
sinon.restore();
116+
processExitStub.restore();
115117
const processExitListener = sinon.stub(process, 'exit');
116118
// Arbitrarily choose an object that throws an error
117119
const errorToThrow = new Error('Something vague and unknown');
@@ -129,14 +131,15 @@ describe('Error Handling', () => {
129131
//Arrange
130132
const loggerDouble = sinon.stub(logger, 'error');
131133
const errorToThrow = new Error('An error that wont be caught 😳');
134+
processExitStub.restore();
132135
const processExitListener = sinon.stub(process, 'exit');
133136

134137
//Act
135138
process.emit('uncaughtException', errorToThrow);
136139

137140
// Assert
138141
expect(loggerDouble.lastCall.firstArg).toMatchObject(errorToThrow);
139-
expect(processExitListener.called).toBe(true);
142+
expect(processExitListener.called).toBe(false);
140143
});
141144

142145
test.todo(

0 commit comments

Comments
 (0)