try different aproch for status

This commit is contained in:
SebClem 2024-04-10 15:13:41 +02:00
parent 0772d909f7
commit 28225dbf67
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
4 changed files with 65 additions and 28 deletions

View File

@ -9,3 +9,5 @@
- `7` => Fail to download snap
- `8` => Fail to stop addon
- `9` => Fail to start addon

View File

@ -10,6 +10,7 @@ import type { WebdavBackup } from "../types/services/webdav.js";
import type { WebdavConfig } from "../types/services/webdavConfig.js";
import { templateToRegexp } from "./backupConfigService.js";
import { getEndpoint } from "./webdavConfigService.js";
import { WebdabStatus } from "../types/status.js";
const PROPFIND_BODY =
'<?xml version="1.0" encoding="utf-8" ?>\
@ -38,6 +39,13 @@ export function checkWebdavLogin(config: WebdavConfig) {
},
(reason) => {
messageManager.error("Fail to connect to Webdav", reason?.message);
const status = statusTools.getStatus();
status.webdav = {
state: WebdabStatus.LOGIN_FAIL,
blocked: true,
last_check: DateTime.now()
}
statusTools.setStatus(status);
logger.error(`Fail to connect to Webdav`);
logger.error(reason);
return Promise.reject(reason);
@ -61,6 +69,13 @@ export async function createBackupFolder(conf: WebdavConfig) {
messageManager.error("Fail to create webdav root folder");
logger.error("Fail to create webdav root folder");
logger.error(error);
const status = statusTools.getStatus();
status.webdav = {
state: WebdabStatus.MK_FOLDER_FAIL,
blocked: true,
last_check: DateTime.now()
}
statusTools.setStatus(status);
return Promise.reject(error);
}
}

View File

@ -1,12 +1,18 @@
import { publish_state } from "../services/homeAssistantService.js";
import logger from "../config/winston.js"
import type { Status } from "../types/status.js";
import logger from "../config/winston.js";
import { type Status, WebdabStatus } from "../types/status.js";
import { DateTime } from "luxon";
let status: Status = {
status: "idle",
last_backup: undefined,
next_backup: undefined,
progress: -1,
webdav: {
state: WebdabStatus.INIT,
last_check: DateTime.now(),
blocked: true,
},
};
export function init() {
@ -32,8 +38,8 @@ export function setStatus(new_state: Status) {
export function setError(message: string, error_code: number) {
// Check if we don't have another error stored
if (status.status != "error") {
status.status = "error"
status.message = message
status.status = "error";
status.message = message;
status.error_code = error_code;
}
logger.error(message);

View File

@ -1,3 +1,13 @@
import type { DateTime } from "luxon";
export enum WebdabStatus {
OK = "OK",
LOGIN_FAIL = "LOGIN_FAIL",
UPLOAD_FAIL = "UPLOAD_FAIL",
CON_ERROR = "CON_ERROR",
INIT = "INIT",
MK_FOLDER_FAIL = "MK_FOLDER_FAIL"
}
export interface Status {
status: string;
@ -6,5 +16,9 @@ export interface Status {
next_backup?: string;
message?: string;
error_code?: number;
webdav: {
state: WebdabStatus;
last_check: DateTime;
blocked: boolean;
};
}