fix(server): http error parsing on endpoints without a default response (#12927)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { TestEmailResponseDto } from 'src/dtos/notification.dto';
|
||||
import { SystemConfigSmtpDto } from 'src/dtos/system-config.dto';
|
||||
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
||||
import { NotificationService } from 'src/services/notification.service';
|
||||
@@ -13,7 +14,7 @@ export class NotificationController {
|
||||
@Post('test-email')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Authenticated({ admin: true })
|
||||
sendTestEmail(@Auth() auth: AuthDto, @Body() dto: SystemConfigSmtpDto) {
|
||||
sendTestEmail(@Auth() auth: AuthDto, @Body() dto: SystemConfigSmtpDto): Promise<TestEmailResponseDto> {
|
||||
return this.service.sendTestEmail(auth.user.id, dto);
|
||||
}
|
||||
}
|
||||
|
||||
3
server/src/dtos/notification.dto.ts
Normal file
3
server/src/dtos/notification.dto.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export class TestEmailResponseDto {
|
||||
messageId!: string;
|
||||
}
|
||||
@@ -616,11 +616,6 @@ describe(NotificationService.name, () => {
|
||||
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.SKIPPED);
|
||||
});
|
||||
|
||||
it('should fail if email could not be sent', async () => {
|
||||
systemMock.get.mockResolvedValue({ notifications: { smtp: { enabled: true } } });
|
||||
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.FAILED);
|
||||
});
|
||||
|
||||
it('should send mail successfully', async () => {
|
||||
systemMock.get.mockResolvedValue({ notifications: { smtp: { enabled: true, from: 'test@immich.app' } } });
|
||||
notificationMock.sendEmail.mockResolvedValue({ messageId: '', response: '' });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
||||
import { DEFAULT_EXTERNAL_DOMAIN } from 'src/constants';
|
||||
import { SystemConfigCore } from 'src/cores/system-config.core';
|
||||
import { OnEmit } from 'src/decorators';
|
||||
@@ -140,7 +140,7 @@ export class NotificationService {
|
||||
try {
|
||||
await this.notificationRepository.verifySmtp(dto.transport);
|
||||
} catch (error) {
|
||||
throw new HttpException('Failed to verify SMTP configuration', HttpStatus.BAD_REQUEST, { cause: error });
|
||||
throw new BadRequestException('Failed to verify SMTP configuration', { cause: error });
|
||||
}
|
||||
|
||||
const { server } = await this.configCore.getConfig({ withCache: false });
|
||||
@@ -152,7 +152,7 @@ export class NotificationService {
|
||||
},
|
||||
});
|
||||
|
||||
await this.notificationRepository.sendEmail({
|
||||
const { messageId } = await this.notificationRepository.sendEmail({
|
||||
to: user.email,
|
||||
subject: 'Test email from Immich',
|
||||
html,
|
||||
@@ -161,6 +161,8 @@ export class NotificationService {
|
||||
replyTo: dto.replyTo || dto.from,
|
||||
smtp: dto.transport,
|
||||
});
|
||||
|
||||
return { messageId };
|
||||
}
|
||||
|
||||
async handleUserSignup({ id, tempPassword }: INotifySignupJob) {
|
||||
@@ -312,10 +314,6 @@ export class NotificationService {
|
||||
imageAttachments: data.imageAttachments,
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
return JobStatus.FAILED;
|
||||
}
|
||||
|
||||
this.logger.log(`Sent mail with id: ${response.messageId} status: ${response.response}`);
|
||||
|
||||
return JobStatus.SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user