Skip to content

Error Handling

Grant Carthew edited this page Feb 20, 2017 · 9 revisions

Description

Whilst using rethinkdb-job-queue errors may occur. There are two ways you can handle errors within your code; Promise catch method or error events.

Promise catch method

If you are calling a method on either a Queue object or a Job object that returns a Promise, you can and should add a catch() method onto the Promise chain so you can log errors that occur.

Rather than list the Queue or Job objects methods that return a Promise, it is easier to list the methods that do not return a Promise.

The following list of object methods do not return a Promise.

All other Queue and Job object methods will return a Promise.

Promise catch Example

This example will catch errors that occur when adding a job to the queue.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()

let job = q.createJob({ data: 'foo' })

q.addJob(job).catch(err => console.error(err))

Error Event

When you create your Queue object you can subscribe to the error event and log or respond to errors within the callback method. The error object will contain an extra property queueId to help identify the Queue object involved in raising the error.

This example will log all errors that occur within the Queue object.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()

q.on('error', (err) => {
  console.log('Queue Id: ' + err.queueId)
  console.error(err)
})

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally