fix: Adjusts in restart instance

This commit is contained in:
Davidson Gomes 2024-08-03 12:54:23 -03:00
parent 7ed1965f57
commit c6db03ffa2
2 changed files with 18 additions and 9 deletions

View File

@ -3,6 +3,7 @@
### Fixed ### Fixed
* BusinessId added on create instances in manager * BusinessId added on create instances in manager
* Adjusts in restart instance
# 2.0.6-rc (2024-08-02 19:23) # 2.0.6-rc (2024-08-02 19:23)

View File

@ -583,6 +583,7 @@ export class InstanceController {
}; };
} catch (error) { } catch (error) {
this.logger.error(error); this.logger.error(error);
return { error: true, message: error.toString() };
} }
} }
@ -591,19 +592,26 @@ export class InstanceController {
const instance = this.waMonitor.waInstances[instanceName]; const instance = this.waMonitor.waInstances[instanceName];
const state = instance?.connectionStatus?.state; const state = instance?.connectionStatus?.state;
switch (state) { if (!state) {
case 'open': throw new BadRequestException('The "' + instanceName + '" instance does not exist');
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) instance.clearCacheChatwoot(); }
if (state == 'close') {
throw new BadRequestException('The "' + instanceName + '" instance is not connected');
} else if (state == 'open') {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) instance.clearCacheChatwoot();
this.logger.info('restarting instance' + instanceName);
this.logger.info('Connection closed, restarting instance' + instanceName);
instance.client?.ws?.close(); instance.client?.ws?.close();
instance.client?.end(new Error('restart')); instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName }); return await this.connectToWhatsapp({ instanceName });
default: } else if (state == 'connecting') {
return await this.connectionState({ instanceName }); instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
} }
} catch (error) { } catch (error) {
this.logger.error(error); this.logger.error(error);
return { error: true, message: error.toString() };
} }
} }