@@ -4,7 +4,10 @@ import { normalizeEnsName } from '@dm3-org/dm3-lib-profile';
4
4
import express from 'express' ;
5
5
import { auth } from './utils' ;
6
6
import { validateNotificationChannel } from './validation/notification/notificationChannelValidation' ;
7
- import { addNewNotificationChannel } from '@dm3-org/dm3-lib-delivery' ;
7
+ import {
8
+ ChannelNotSupportedError ,
9
+ addNewNotificationChannel ,
10
+ } from '@dm3-org/dm3-lib-delivery' ;
8
11
import { getDeliveryServiceProperties } from './config/getDeliveryServiceProperties' ;
9
12
import { IDatabase } from './persistance/getDatabase' ;
10
13
@@ -65,12 +68,12 @@ export default () => {
65
68
66
69
// Defining a route to handle POST requests for adding an notification channel
67
70
router . post ( '/:ensName' , async ( req , res , next ) => {
71
+ // Extracting recipientValue & notificationChannelType from the request body
72
+ const { recipientValue, notificationChannelType } = req . body ;
73
+
68
74
try {
69
75
const account = normalizeEnsName ( req . params . ensName ) ;
70
76
71
- // Extracting recipientValue & notificationChannelType from the request body
72
- const { recipientValue, notificationChannelType } = req . body ;
73
-
74
77
// Validate req.body data
75
78
const { isValid, errorMessage } = validateNotificationChannel (
76
79
notificationChannelType ,
@@ -106,9 +109,19 @@ export default () => {
106
109
// Sending a success response
107
110
res . sendStatus ( 200 ) ;
108
111
}
109
- } catch ( e ) {
110
- // Passing the error to the next middleware
111
- next ( e ) ;
112
+ } catch ( e : any ) {
113
+ if (
114
+ e instanceof ChannelNotSupportedError ||
115
+ e . message === 'Invalid config.yml'
116
+ ) {
117
+ // return the error for not supported channels
118
+ res . sendStatus ( 400 ) . json ( {
119
+ error : `Notification channel ${ notificationChannelType } is currently not supported yet by the DS` ,
120
+ } ) ;
121
+ } else {
122
+ // Passing the error to the next middleware
123
+ next ( e ) ;
124
+ }
112
125
}
113
126
} ) ;
114
127
0 commit comments