forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.ts
More file actions
40 lines (35 loc) · 1.5 KB
/
Copy patherror.ts
File metadata and controls
40 lines (35 loc) · 1.5 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
/**
* Create an error message block
* @param dom The DOM on which dom.createElement will be called
* @param err The error message string to display (or an error object)
* @param backgroundColor Background color. Default: '#fee'
* @param err2 Is the second param is a string, you can put the original Error in here
* @returns A div element with the err string
*
* This will return a DOM element you can put in the UI as a notice for the user
* Meanwhile the stack is dumped to the console for the developer, so you actually know
* where it happened!
*/
/* eslint-disable no-console */
import { cancelButton } from '../widgets'
export function errorMessageBlock (dom: HTMLDocument, err: string | Error, backgroundColor?: string, err2?: Error): HTMLDivElement {
const div = dom.createElement('div')
/* tslint:disable-next-line */ // Too complex for TS?
// @ts-ignore
const errorObject:Error = err2 || err instanceof Error ? err : null
if (errorObject) {
console.error(`errorMessageBlock: ${errorObject} at: ${errorObject.stack || '??'}`, errorObject) // @@ pick one
div.textContent = errorObject.message
} else {
div.textContent = err as string
}
div.appendChild(cancelButton(dom, () => { if (div.parentNode) div.parentNode.removeChild(div) }))
.style = 'width: 2em; height: 2em; align: right;'
div.setAttribute(
'style',
'margin: 0.1em; padding: 0.5em; border: 0.05em solid gray; background-color: ' +
(backgroundColor || '#fee') +
'; color:black;'
)
return div
}