Skip to content

Commit

Permalink
fix(exchange): use more granular error classes for reporting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed May 4, 2024
1 parent 2cc06c1 commit 3b3e640
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/lib/exchange/errors/exchange-fan-out-queue-type.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c)
* Weyoss <weyoss@protonmail.com>
* https://github.com/weyoss
*
* This source code is licensed under the MIT license found in the LICENSE file
* in the root directory of this source tree.
*/

import { ExchangeFanOutError } from './exchange-fan-out.error.js';

export class ExchangeFanOutQueueTypeError extends ExchangeFanOutError {}
1 change: 1 addition & 0 deletions src/lib/exchange/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export { ExchangeInvalidFanOutParamsError } from './exchange-invalid-fan-out-par
export { ExchangeInvalidQueueParamsError } from './exchange-invalid-queue-params.error.js';
export { ExchangeFanOutExchangeHasBoundQueuesError } from './exchange-fan-out-exchange-has-bound-queues.error.js';
export { ExchangeQueueIsNotBoundToExchangeError } from './exchange-queue-is-not-bound-to-exchange.error.js';
export { ExchangeFanOutQueueTypeError } from './exchange-fan-out-queue-type.error.js';
8 changes: 2 additions & 6 deletions src/lib/exchange/exchange-fan-out/exchange-fan-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
IQueueProperties,
} from '../../queue/index.js';
import {
ExchangeFanOutError,
ExchangeFanOutExchangeHasBoundQueuesError,
ExchangeFanOutQueueTypeError,
ExchangeQueueIsNotBoundToExchangeError,
} from '../errors/index.js';
import { ExchangeAbstract } from '../exchange-abstract.js';
Expand Down Expand Up @@ -135,11 +135,7 @@ export class ExchangeFanOut extends ExchangeAbstract<string> {
exchangeQueueProperties.queueType !==
queueProperties.queueType
)
cb(
new ExchangeFanOutError(
'Binding different types of queues to the same exchange is not allowed.',
),
);
cb(new ExchangeFanOutQueueTypeError());
else cb(null, queueProperties);
},
);
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/exchanges/fanout-exchange/test00008.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { test, expect } from '@jest/globals';
import {
EQueueDeliveryModel,
EQueueType,
ExchangeFanOutError,
ExchangeFanOutQueueTypeError,
} from '../../../../src/lib/index.js';
import { getFanOutExchange } from '../../../common/exchange.js';
import { getQueue } from '../../../common/queue.js';
Expand All @@ -37,6 +37,6 @@ test('ExchangeFanOut: binding different types of queues', async () => {
);

await expect(fanOutExchangeManager.bindQueueAsync(q2, 'e1')).rejects.toThrow(
ExchangeFanOutError,
ExchangeFanOutQueueTypeError,
);
});

0 comments on commit 3b3e640

Please sign in to comment.