fix: Update PrivacySetting groupadd type and enhance error handling in fetchInstances route

- Changed the type of `groupadd` in `PrivacySetting` from `WAPrivacyValue` to `any` to allow for more flexible data handling.
- Wrapped the `fetchInstances` route in a try-catch block to improve error handling and logging, ensuring that any errors are logged and a proper error response is returned to the client.

These changes enhance the robustness of the API and improve type flexibility in the DTO.
This commit is contained in:
Davidson Gomes 2024-12-11 15:53:58 -03:00
parent ca474236b0
commit 555fa606ea
2 changed files with 20 additions and 14 deletions

View File

@ -84,7 +84,7 @@ class PrivacySetting {
status: WAPrivacyValue; status: WAPrivacyValue;
online: WAPrivacyOnlineValue; online: WAPrivacyOnlineValue;
last: WAPrivacyValue; last: WAPrivacyValue;
groupadd: WAPrivacyValue; groupadd: any;
} }
export class PrivacySettingDto { export class PrivacySettingDto {

View File

@ -99,6 +99,7 @@ export class InstanceRouter extends RouterBroker {
return res.status(HttpStatus.OK).json(response); return res.status(HttpStatus.OK).json(response);
}) })
.get(this.routerPath('fetchInstances', false), ...guards, async (req, res) => { .get(this.routerPath('fetchInstances', false), ...guards, async (req, res) => {
try {
logger.verbose('request received in fetchInstances'); logger.verbose('request received in fetchInstances');
logger.verbose('request body: '); logger.verbose('request body: ');
logger.verbose(req.body); logger.verbose(req.body);
@ -115,6 +116,11 @@ export class InstanceRouter extends RouterBroker {
}); });
return res.status(HttpStatus.OK).json(response); return res.status(HttpStatus.OK).json(response);
} catch (error) {
logger.error('fetchInstances');
logger.error(error);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ error: true, message: error.message });
}
}) })
.post(this.routerPath('setPresence'), ...guards, async (req, res) => { .post(this.routerPath('setPresence'), ...guards, async (req, res) => {
logger.verbose('request received in setPresence'); logger.verbose('request received in setPresence');