Skip to content

Commit fec755c

Browse files
committed
Add info
1 parent 2a4c2a7 commit fec755c

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/handle.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { exit } = require('process')
44

5-
const { parsePromise } = require('./promise')
5+
const { getInfo } = require('./info')
66
const { getMessage } = require('./message')
77

88
// Generic event handler for all events.
@@ -15,27 +15,18 @@ const handleEvent = async function({
1515
secondPromiseState,
1616
secondPromiseValue,
1717
}) {
18-
const { promiseState, promiseValue: promiseValueA } = await parsePromise({
18+
const info = await getInfo({
1919
eventName,
20+
error,
2021
promise,
2122
promiseValue,
22-
})
23-
const message = getMessage({
24-
eventName,
25-
promiseState,
26-
promiseValue: promiseValueA,
2723
secondPromiseState,
2824
secondPromiseValue,
29-
error,
3025
})
3126

32-
handlerFunc({
33-
eventName,
34-
promiseState,
35-
promiseValue: promiseValueA,
36-
error,
37-
message,
38-
})
27+
const message = getMessage(info)
28+
29+
handlerFunc({ ...info, message })
3930

4031
exitProcess({ eventName, exitOnExceptions })
4132
}

src/promise.js renamed to src/info.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
'use strict'
22

3+
// Retrieve `info` object representing the current error information
4+
const getInfo = async function({
5+
eventName,
6+
error,
7+
promise,
8+
promiseValue,
9+
secondPromiseState,
10+
secondPromiseValue,
11+
}) {
12+
const { promiseState, promiseValue: promiseValueA } = await parsePromise({
13+
eventName,
14+
promise,
15+
promiseValue,
16+
})
17+
18+
return {
19+
eventName,
20+
error,
21+
promiseState,
22+
promiseValue: promiseValueA,
23+
secondPromiseState,
24+
secondPromiseValue,
25+
}
26+
}
27+
328
// Retrieve promise's resolved/rejected state and value.
429
const parsePromise = async function({ eventName, promise, promiseValue }) {
530
// `uncaughtException` and `warning` events do not have `promise`.
@@ -23,5 +48,5 @@ const parsePromise = async function({ eventName, promise, promiseValue }) {
2348
}
2449

2550
module.exports = {
26-
parsePromise,
51+
getInfo,
2752
}

0 commit comments

Comments
 (0)