diff --git a/src/groups/dao/groups.dao.ts b/src/groups/dao/groups.dao.ts index 885b2f5acb163b7710d70e1cba7629743a453a55..682c742fe1df1316af7bfa491e419b4ea1b80af1 100644 --- a/src/groups/dao/groups.dao.ts +++ b/src/groups/dao/groups.dao.ts @@ -1,4 +1,8 @@ -import { Injectable } from '@nestjs/common'; +import { + Injectable, + NotFoundException, + InternalServerErrorException, +} from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { CreateGroupDto } from '../dto/create-group.dto'; @@ -16,6 +20,7 @@ export class GroupsDao { new Promise((resolve, reject) => { this._groupModel.find({}, {}, {}, (err, value) => { if (err) reject(err.message); + if (!value) reject('No values'); resolve(value); }); }); @@ -24,6 +29,7 @@ export class GroupsDao { new Promise((resolve, reject) => { this._groupModel.findOne({ id: id }, {}, {}, (err, value) => { if (err) reject(err.message); + if (!value) reject(new NotFoundException()); resolve(value); }); }); @@ -32,6 +38,7 @@ export class GroupsDao { new Promise((resolve, reject) => { new this._groupModel(group).save((err, value) => { if (err) reject(err.message); + if (!value) reject(new InternalServerErrorException()); resolve(value); }); }); @@ -50,6 +57,7 @@ export class GroupsDao { }, (err, value) => { if (err) reject(err.message); + if (value.matchedCount === 0) reject(new NotFoundException()); resolve(value); }, ); diff --git a/src/interceptors/http.interceptor.ts b/src/interceptors/http.interceptor.ts index ebef03fe0ef69906c7693c2f8463ef75f03e819d..934929f681ab0a00077de9148aaa3c51348e1f72 100644 --- a/src/interceptors/http.interceptor.ts +++ b/src/interceptors/http.interceptor.ts @@ -52,7 +52,12 @@ export class HttpInterceptor implements NestInterceptor { tap({ next: (_) => this._logger.log(!!_ ? JSON.stringify(_) : 'NO CONTENT', logCtx), - error: (_) => this._logger.error(_.message, JSON.stringify(_), logCtx), + error: (_) => + this._logger.error( + _?.message ?? 'unspecified error', + JSON.stringify(_), + logCtx, + ), }), ); };