Skip to content

Commit

Permalink
fix: use namespaced errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed May 10, 2024
1 parent 9c1fa7a commit 637096b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/message/_/_delete-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
MessageError,
MessageInvalidParametersError,
MessageMessageInProcessError,
MessageMessageNotDeletedError,
MessageMessageNotFoundError,
} from '../errors/index.js';
import { EMessageProperty, EMessagePropertyStatus } from '../types/index.js';
Expand Down Expand Up @@ -99,7 +100,7 @@ export function _deleteMessage(
} else if (reply === 'MESSAGE_IN_PROCESS') {
cb(new MessageMessageInProcessError());
} else if (reply === 'MESSAGE_NOT_DELETED') {
cb(new MessageMessageNotFoundError());
cb(new MessageMessageNotDeletedError());
} else if (reply === 'INVALID_PARAMETERS') {
cb(new MessageInvalidParametersError());
} else {
Expand Down
1 change: 1 addition & 0 deletions src/lib/message/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export { MessageMessagePropertyError } from './message-message-property.error.js
export { MessageMessageInProcessError } from './message-message-in-process.error.js';
export { MessageInvalidParametersError } from './message-invalid-parameters.error.js';
export { MessageMessageNotRequeuableError } from './message-message-not-requeuable.error.js';
export { MessageMessageNotDeletedError } from './message-message-not-deleted.error.js';
12 changes: 12 additions & 0 deletions src/lib/message/errors/message-message-not-deleted.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 { MessageError } from './message.error.js';

export class MessageMessageNotDeletedError extends MessageError {}
10 changes: 4 additions & 6 deletions src/lib/queue-messages/_/_validate-queue-extended-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
*/

import { ICallback, IRedisClient } from 'redis-smq-common';
import {
ConsumerConsumerGroupIdNotSupportedError,
ConsumerConsumerGroupIdRequiredError,
} from '../../consumer/index.js';
import { _getQueueProperties } from '../../queue/_/_get-queue-properties.js';
import { EQueueDeliveryModel, IQueueParsedParams } from '../../queue/index.js';
import { QueueMessagesConsumerGroupIdNotSupportedError } from '../errors/queue-messages-consumer-group-id-not-supported.error.js';
import { QueueMessagesConsumerGroupIdRequiredError } from '../errors/queue-messages-consumer-group-id-required.error.js';

export function _validateQueueExtendedParams(
redisClient: IRedisClient,
Expand All @@ -30,12 +28,12 @@ export function _validateQueueExtendedParams(
properties?.deliveryModel === EQueueDeliveryModel.PUB_SUB &&
!groupId
) {
cb(new ConsumerConsumerGroupIdRequiredError());
cb(new QueueMessagesConsumerGroupIdRequiredError());
} else if (
properties?.deliveryModel === EQueueDeliveryModel.POINT_TO_POINT &&
groupId
) {
cb(new ConsumerConsumerGroupIdNotSupportedError());
cb(new QueueMessagesConsumerGroupIdNotSupportedError());
} else cb();
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/lib/queue-messages/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
*/

export { QueueMessagesError } from './queue-messages.error.js';
export { QueueMessagesConsumerGroupIdRequiredError } from './queue-messages-consumer-group-id-required.error.js';
export { QueueMessagesConsumerGroupIdNotSupportedError } from './queue-messages-consumer-group-id-not-supported.error.js';
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 { QueueMessagesError } from './queue-messages.error.js';

export class QueueMessagesConsumerGroupIdNotSupportedError extends QueueMessagesError {}
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 { QueueMessagesError } from './queue-messages.error.js';

export class QueueMessagesConsumerGroupIdRequiredError extends QueueMessagesError {}

0 comments on commit 637096b

Please sign in to comment.