Skip to content

Commit 74c2531

Browse files
committed
fix: better error handling
1 parent bec9b78 commit 74c2531

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

src/modules/users/users.service.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ export class UsersService {
122122
const user = await this.updateUserTransactional(dto);
123123

124124
if (!user.isOk || !user.response) {
125-
if (user.code === 'A025') {
126-
return {
127-
isOk: false,
128-
...ERRORS.USER_NOT_FOUND,
129-
};
130-
}
131-
132-
if (user.code === 'A023') {
133-
return {
134-
isOk: false,
135-
...ERRORS.CANT_GET_CREATED_USER_WITH_INBOUNDS,
136-
};
137-
}
138-
139125
return {
140126
isOk: false,
141127
...ERRORS.UPDATE_USER_ERROR,
@@ -172,6 +158,23 @@ export class UsersService {
172158
response: user.response.user,
173159
};
174160
} catch (error) {
161+
if (error instanceof Error && error.message === ERRORS.USER_NOT_FOUND.code) {
162+
return {
163+
isOk: false,
164+
...ERRORS.USER_NOT_FOUND,
165+
};
166+
}
167+
168+
if (
169+
error instanceof Error &&
170+
error.message === ERRORS.CANT_GET_CREATED_USER_WITH_INBOUNDS.code
171+
) {
172+
return {
173+
isOk: false,
174+
...ERRORS.CANT_GET_CREATED_USER_WITH_INBOUNDS,
175+
};
176+
}
177+
175178
this.logger.error(error);
176179

177180
return { isOk: false, ...ERRORS.UPDATE_USER_ERROR };
@@ -307,23 +310,6 @@ export class UsersService {
307310
},
308311
};
309312
} catch (error) {
310-
if (error instanceof Error && error.message === ERRORS.USER_NOT_FOUND.code) {
311-
return {
312-
isOk: false,
313-
...ERRORS.USER_NOT_FOUND,
314-
};
315-
}
316-
317-
if (
318-
error instanceof Error &&
319-
error.message === ERRORS.CANT_GET_CREATED_USER_WITH_INBOUNDS.code
320-
) {
321-
return {
322-
isOk: false,
323-
...ERRORS.CANT_GET_CREATED_USER_WITH_INBOUNDS,
324-
};
325-
}
326-
327313
throw error;
328314
}
329315
}

0 commit comments

Comments
 (0)