-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathExceptionDialogModel.ts
More file actions
94 lines (79 loc) · 2.7 KB
/
Copy pathExceptionDialogModel.ts
File metadata and controls
94 lines (79 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
*
* Copyright © 2026 Extremely Heavy Industries Inc.
*/
import type {HoistException} from '@xh/hoist/exception';
import {ExceptionHandlerOptions, HoistModel, XH} from '@xh/hoist/core';
import {action, observable, makeObservable, bindable} from '@xh/hoist/mobx';
/**
* Manages the default display of exceptions.
*
* Currently, we allow only a single exception (the latest) to be displayed at a time.
* Consider modifying to allow stacking, as with Message.
*
* @internal
*/
export class ExceptionDialogModel extends HoistModel {
override xhImpl = true;
@observable.ref
displayData: {exception: HoistException; options: ExceptionHandlerOptions};
@observable
detailsIsOpen = false;
/** Exception currently being displayed */
get exception(): HoistException {
return this.displayData?.exception ?? null;
}
/** Options for exception currently being displayed */
get options(): any {
return this.displayData?.options ?? {};
}
/** Optional user supplied message */
@bindable
userMessage: string = '';
constructor() {
super();
makeObservable(this);
}
@action
show(exception: HoistException, options: ExceptionHandlerOptions) {
if (this.displayData?.options.requireReload) return;
this.displayData = {exception, options};
}
@action
showDetails(exception: HoistException, options: ExceptionHandlerOptions) {
this.show(exception, options);
this.openDetails();
}
@action
close() {
this.displayData = null;
this.detailsIsOpen = false;
}
@action
openDetails() {
this.detailsIsOpen = true;
this.userMessage = '';
}
async sendReportAsync() {
const {exception, userMessage, options} = this;
const success = await XH.exceptionHandler.logOnServerAsync({
exception,
userMessage,
userAlerted: true
});
if (success) {
await XH.alert({title: 'Message Sent', message: 'Your error has been reported.'});
this.userMessage = null;
if (!options.requireReload) this.close();
} else {
const email = XH.configService.get('xhEmailSupport', 'none'),
message =
email && email != 'none'
? `Failed to send message. Please seek out additional support by contacting: '${email}'.`
: `Failed to send message. Please contact support directly.`;
await XH.alert({title: 'Error', message});
}
}
}