Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @codexteam/hawk.nodejs with all npm packages installed. Try it out:

var hawkNodejs = require("@codexteam/hawk.nodejs")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@codexteam/hawk.nodejs v1.2.1

Node.js catcher for Hawk

hawk.nodejs

Node.js errors Catcher module for Hawk.so

Usage

Register an account and get a project token.

Install module

Use npm to install Catcher

$ npm install @codexteam/hawk.nodejs --save

Download and require node.js file

You can download this repository and require Hawk.nodejs file in your project.

require './hawk.nodejs/src/hawk';

Init HawkCatcher

Create an instance with token to the entry point of your project.

var hawkCatcher = require('@codexteam/hawk.nodejs')({
  accessToken: "69d86244-f792-47ad-8e9a-23fee358e062"
});

Custom Hawk server

If you want to use custom Hawk server then pass a url to this catcher.

var hawkCatcher = require('@codexteam/hawk.nodejs')({
  accessToken: "69d86244-f792-47ad-8e9a-23fee358e062",
  url: "https://myownhawk.com/catcher/nodejs"
});

Usage

You can catch global Exceptions

hawkCatcher.initGlobalCatcher();

If you provide callback function – it will be called after Exception would be caught by Hawk.

hawkCatcher.initGlobalCatcher(function (error, response, body) {
  console.log('Hawk response: ', body);
});

Catch exception manually

You can catch exceptions by yourself without enabling handlers.

try {
  throw new Exception("");
} catch (e) {
  hawkCatcher.catchException(e, {comment: "Exception in general module"});
}

The catchException method has two optional arguments:

  • custom - [optional] dictionary with the following structure
    • comment - error description
  • callback - [optional] callback function
try {
  throw new Exception('');
} catch (e) {
  hawkCatcher.catchExceptionPromise(e, {comment: 'Exception in general module'})
    .then(function (result) {
      console.log(result);
    })
    .catch(function (err) {
      console.log('Error occured: ', err);
    });
}

The catchExceptionPromise method returns Promise and has one optional argument:

  • custom - [optional] dictionary with the following structure
    • comment - error description

Links

Repository: https://github.com/codex-team/hawk.nodejs

Report a bug: https://github.com/codex-team/hawk.nodejs/issues

CodeX Team: https://ifmo.su

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free