update status for incorrect api token and bad workspace name
This commit is contained in:
35
src/main.ts
35
src/main.ts
@@ -36,8 +36,6 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
|
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|
||||||
this.updateStatus(InstanceStatus.Ok)
|
|
||||||
|
|
||||||
this.workspaceId = undefined
|
this.workspaceId = undefined
|
||||||
this.projects = [{ id: '0', label: 'None' }]
|
this.projects = [{ id: '0', label: 'None' }]
|
||||||
|
|
||||||
@@ -55,6 +53,10 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
await this.initToggleConnection()
|
await this.initToggleConnection()
|
||||||
|
|
||||||
this.updateActions()
|
this.updateActions()
|
||||||
|
|
||||||
|
if (this.toggl && this.workspaceId) {
|
||||||
|
this.updateStatus(InstanceStatus.Ok)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async configUpdated(config: ModuleConfig): Promise<void> {
|
async configUpdated(config: ModuleConfig): Promise<void> {
|
||||||
@@ -69,17 +71,20 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
this.log('debug', 'api token changed. init new toggle connection')
|
this.log('debug', 'api token changed. init new toggle connection')
|
||||||
this.toggl = undefined
|
this.toggl = undefined
|
||||||
await this.initToggleConnection()
|
await this.initToggleConnection()
|
||||||
}
|
} else if (workSpaceDefaultChanged) {
|
||||||
if (workSpaceDefaultChanged) {
|
|
||||||
this.log('debug', 'workspace default changed. reload workspaces')
|
this.log('debug', 'workspace default changed. reload workspaces')
|
||||||
await this.getWorkspace()
|
await this.getWorkspace()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateActions()
|
this.updateActions()
|
||||||
this.updateVariables()
|
this.updateVariables()
|
||||||
|
if (this.toggl && this.workspaceId) {
|
||||||
|
this.updateStatus(InstanceStatus.Ok)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateVariables(): void {
|
updateVariables(): void {
|
||||||
throw new Error('Method not implemented.')
|
this.log('error', 'updateVariables not implemented')
|
||||||
|
//throw new Error('Method not implemented.')
|
||||||
}
|
}
|
||||||
updateActions(): void {
|
updateActions(): void {
|
||||||
UpdateActions(this)
|
UpdateActions(this)
|
||||||
@@ -98,20 +103,23 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initToggleConnection(): Promise<void> {
|
async initToggleConnection(): Promise<void> {
|
||||||
if (this.config.apiToken!.length > 0) {
|
if (this.config.apiToken && this.config.apiToken.length > 0) {
|
||||||
this.toggl = new Toggl({
|
this.toggl = new Toggl({
|
||||||
auth: {
|
auth: {
|
||||||
token: this.config.apiToken!,
|
token: this.config.apiToken,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const logged: string = await this.toggl.me.logged()
|
|
||||||
this.log('debug', logged)
|
const resp = await this.toggl.me.logged()
|
||||||
if (logged === 'OK') {
|
if (resp !== '') {
|
||||||
await this.getWorkspace()
|
this.log('warn', 'error during token check: ' + resp)
|
||||||
await this.getCurrentTimer()
|
this.toggl = undefined
|
||||||
|
this.updateStatus(InstanceStatus.AuthenticationFailure, resp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
await this.getWorkspace()
|
||||||
|
await this.getCurrentTimer()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCurrentTimer(): Promise<number | null> {
|
async getCurrentTimer(): Promise<number | null> {
|
||||||
@@ -175,6 +183,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
if (this.workspaceId == undefined) {
|
if (this.workspaceId == undefined) {
|
||||||
// no workspace found
|
// no workspace found
|
||||||
//console.log('result ' + JSON.stringify(workspaces, null, 4))
|
//console.log('result ' + JSON.stringify(workspaces, null, 4))
|
||||||
|
this.updateStatus(InstanceStatus.BadConfig, 'No workspace found')
|
||||||
this.log('debug', 'No workspace found')
|
this.log('debug', 'No workspace found')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user