Skip to content

Commit eac1259

Browse files
committed
Fixed resolveDkimId method
This method incorrectly caught all errors from the Wildduck API as internal server errors hence failed when adding a new domain Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
1 parent 8f3cba7 commit eac1259

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

src/dkim/dkim.service.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common'
22
import { HttpService } from '@nestjs/axios'
3-
import { AxiosResponse } from 'axios'
3+
import { AxiosError, AxiosResponse } from 'axios'
44
import { ConfigService } from 'src/config/config.service'
55
import { DomainsService } from 'src/domains/domains.service'
66
import { User } from 'src/users/user.entity'
@@ -23,21 +23,20 @@ export class DkimService {
2323
try {
2424
ApiResponse = await this.httpService.get(`/dkim/resolve/${domain}`).toPromise()
2525
} catch (error) {
26+
if (error instanceof AxiosError && (error.response.data.error || !error.response.data.success)) {
27+
switch (error.response.data.code) {
28+
case 'DkimNotFound':
29+
throw new NotFoundException(`No DKIM key found for domain: ${domain}`, 'DkimNotFoundError')
30+
31+
default:
32+
this.logger.error(error.response.data)
33+
throw new InternalServerErrorException('Unknown error')
34+
}
35+
}
2636
this.logger.error(error.message)
2737
throw new InternalServerErrorException('Backend service not reachable', 'WildduckApiError')
2838
}
2939

30-
if (ApiResponse.data.error || !ApiResponse.data.success) {
31-
switch (ApiResponse.data.code) {
32-
case 'DkimNotFound':
33-
throw new NotFoundException(`No DKIM key found for domain: ${domain}`, 'DkimNotFoundError')
34-
35-
default:
36-
this.logger.error(ApiResponse.data)
37-
throw new InternalServerErrorException('Unknown error')
38-
}
39-
}
40-
4140
return ApiResponse.data.id
4241
}
4342

0 commit comments

Comments
 (0)