@@ -6,7 +6,7 @@ import Auth from './Auth';
6
6
const PUSH_STATUS_COLLECTION = '_PushStatus' ;
7
7
const JOB_STATUS_COLLECTION = '_JobStatus' ;
8
8
9
- const incrementOp = function ( object = { } , key , amount = 1 ) {
9
+ const incrementOp = function ( object = { } , key , amount = 1 ) {
10
10
if ( ! object [ key ] ) {
11
11
object [ key ] = { __op : 'Increment' , amount : amount } ;
12
12
} else {
@@ -91,7 +91,7 @@ export function jobStatusHandler(config) {
91
91
const objectId = newObjectId ( config . objectIdSize ) ;
92
92
const database = config . database ;
93
93
const handler = statusHandler ( JOB_STATUS_COLLECTION , database ) ;
94
- const setRunning = function ( jobName , params ) {
94
+ const setRunning = function ( jobName , params ) {
95
95
const now = new Date ( ) ;
96
96
jobStatus = {
97
97
objectId,
@@ -107,27 +107,30 @@ export function jobStatusHandler(config) {
107
107
return handler . create ( jobStatus ) ;
108
108
} ;
109
109
110
- const setMessage = function ( message ) {
110
+ const setMessage = function ( message ) {
111
111
if ( ! message || typeof message !== 'string' ) {
112
112
return Promise . resolve ( ) ;
113
113
}
114
114
return handler . update ( { objectId } , { message } ) ;
115
115
} ;
116
116
117
- const setSucceeded = function ( message ) {
117
+ const setSucceeded = function ( message ) {
118
118
return setFinalStatus ( 'succeeded' , message ) ;
119
119
} ;
120
120
121
- const setFailed = function ( message ) {
121
+ const setFailed = function ( message ) {
122
122
return setFinalStatus ( 'failed' , message ) ;
123
123
} ;
124
124
125
- const setFinalStatus = function ( status , message = undefined ) {
125
+ const setFinalStatus = function ( status , message = undefined ) {
126
126
const finishedAt = new Date ( ) ;
127
127
const update = { status, finishedAt } ;
128
128
if ( message && typeof message === 'string' ) {
129
129
update . message = message ;
130
130
}
131
+ if ( message instanceof Error && typeof message . message === 'string' ) {
132
+ update . message = message . message ;
133
+ }
131
134
return handler . update ( { objectId } , update ) ;
132
135
} ;
133
136
@@ -144,7 +147,7 @@ export function pushStatusHandler(config, existingObjectId) {
144
147
const database = config . database ;
145
148
const handler = restStatusHandler ( PUSH_STATUS_COLLECTION , config ) ;
146
149
let objectId = existingObjectId ;
147
- const setInitial = function ( body = { } , where , options = { source : 'rest' } ) {
150
+ const setInitial = function ( body = { } , where , options = { source : 'rest' } ) {
148
151
const now = new Date ( ) ;
149
152
let pushTime = now . toISOString ( ) ;
150
153
let status = 'pending' ;
@@ -193,7 +196,7 @@ export function pushStatusHandler(config, existingObjectId) {
193
196
} ) ;
194
197
} ;
195
198
196
- const setRunning = function ( batches ) {
199
+ const setRunning = function ( batches ) {
197
200
logger . verbose (
198
201
`_PushStatus ${ objectId } : sending push to installations with %d batches` ,
199
202
batches
@@ -210,7 +213,7 @@ export function pushStatusHandler(config, existingObjectId) {
210
213
) ;
211
214
} ;
212
215
213
- const trackSent = function (
216
+ const trackSent = function (
214
217
results ,
215
218
UTCOffset ,
216
219
cleanupInstallations = process . env
@@ -310,7 +313,7 @@ export function pushStatusHandler(config, existingObjectId) {
310
313
} ) ;
311
314
} ;
312
315
313
- const complete = function ( ) {
316
+ const complete = function ( ) {
314
317
return handler . update (
315
318
{ objectId } ,
316
319
{
@@ -320,7 +323,7 @@ export function pushStatusHandler(config, existingObjectId) {
320
323
) ;
321
324
} ;
322
325
323
- const fail = function ( err ) {
326
+ const fail = function ( err ) {
324
327
if ( typeof err === 'string' ) {
325
328
err = { message : err } ;
326
329
}
0 commit comments