🦴 Adds result service

This commit is contained in:
Rune Harlyk
2024-02-23 12:07:01 +01:00
parent 22b54261f0
commit 2b810cba7b
3 changed files with 31 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { errorLogs, latestErrorLog } from '$lib/stores';
import type { Result } from '$lib/utilities';
class ResultService {
public handleResult(result: Result<unknown, string>, tag?: string) {
if (result.isErr()) {
const errorLogEntry = { tag, message: result.inner, exception: result.exception };
latestErrorLog.set(errorLogEntry);
errorLogs.update((entries) => {
entries.push(errorLogEntry);
return entries;
});
}
return result;
}
}
export default new ResultService();