-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCatchError.njs
More file actions
47 lines (36 loc) · 1.04 KB
/
CatchError.njs
File metadata and controls
47 lines (36 loc) · 1.04 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
import Nullstack from 'nullstack'
import { appendFileSync } from 'fs'
const error = new Error('Panic in the system, someone missconfigured me!')
class CatchError extends Nullstack {
static async logError({ message, environment }) {
const folder = environment.production ? '.production' : '.development'
appendFileSync(`${folder}/exceptions.txt`, `${message}\n`)
}
static async getServerFunction() {
throw error
}
async oneErrorPls() {
throw error
}
async hydrate({ params }) {
setTimeout(() => (this.hydrated = true), 0)
if (params.error === 'hydrate') {
await this.vaidamerdanoclient()
}
}
async initiate({ params, page }) {
if (params.error === 'initiate' && page.status === 200) {
this.vaidamerdanoserver()
} else if (params.error === 'initiateServerFunction') {
await this.getServerFunction()
}
}
render() {
return (
<div data-hydrated={this.hydrated}>
<button onclick={this.oneErrorPls}> Error </button>
</div>
)
}
}
export default CatchError