Skip to content

Commit 421980f

Browse files
edilsonoliveiramaDavidsonGomes
authored andcommitted
fix(instance): return 200 with disconnected status instead of 400 on #20
GET /instance/status was calling ensureClientConnected, which returns an error when the WhatsApp client exists but is not connected (e.g. after the user manually removes the device from their phone). This caused the endpoint to return HTTP 400 until the container was restarted, making it impossible for clients to detect the disconnected state without restarting the server. Status is a read-only query: it should report the current state, not require an active connection to do so. The fix reads clientPointer directly and returns Connected=false/LoggedIn=false when the client is nil or disconnected, without attempting reconnection. Fixes #20
1 parent d1ff63e commit 421980f

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

pkg/instance/service/instance_service.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,13 @@ func (i instances) Logout(instance *instance_model.Instance) (*instance_model.In
376376
}
377377

378378
func (i instances) Status(instance *instance_model.Instance) (*StatusStruct, error) {
379-
client, err := i.ensureClientConnected(instance.Id)
380-
if err != nil {
381-
return nil, err
379+
client := i.clientPointer[instance.Id]
380+
381+
if client == nil {
382+
return &StatusStruct{
383+
Connected: false,
384+
LoggedIn: false,
385+
}, nil
382386
}
383387

384388
isConnected := client.IsConnected()
@@ -391,14 +395,12 @@ func (i instances) Status(instance *instance_model.Instance) (*StatusStruct, err
391395
name = client.Store.PushName
392396
}
393397

394-
status := &StatusStruct{
398+
return &StatusStruct{
395399
Connected: isConnected,
396400
LoggedIn: isLoggedIn,
397401
myJid: myJid,
398402
Name: name,
399-
}
400-
401-
return status, nil
403+
}, nil
402404
}
403405

404406
func (i instances) GetQr(instance *instance_model.Instance) (*QrcodeStruct, error) {

0 commit comments

Comments
 (0)