Code Monkey home page Code Monkey logo

pg_error_parser's Introduction

pg_error_parser

A micro-module to make sense of error messages in postgresql. Works well with the pg module.

npm install pg_error_parser

Usage

format(error)

Takes an error object and adds more information to it. Useful when logging error objects and needing to see some normalized data.

Error lookups are based on the sqlState key of the error object.

Format will add the following keys to the error object:

code_name

Values such as not_null_violation, unique_violation, or invalid_sql_statement_name.

code_level

The severity of the error, either info, warning, or error.

code_group_name

A human readable name for this type of error like Integrity Constraint Violation, Invalid Transaction State, or Data Exception.

var pg = require('pg');
var pgep = require('pg_error_parser');
var client = new pg.Client();


client.query(text, params, function(err, result) {
  done();
  if (err) {
    err = pgep.format(err);
    // error object now has additional keys
    console.error(err);
    return callback(err);
  }
  callback(null, result);
});

getLevel(code)

Returns the error level of a given code.

getLevel('23505')
// error

getLevel('01P01')
// warn

getLevel('00000')
// info

getCodeName(code)

Returns the code name of a given code.

getLevel('23505')
// unique_violation

getLevel('01P01')
// deprecated_feature

getLevel('00000')
// successful_completion

getGroupName(code)

Returns the human readable name for and error if this type.

getLevel('23505')
// Integrity Constraint Violation

getLevel('01P01')
// Warning

getLevel('00000')
// Successful Completion

License

MIT

pg_error_parser's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.