npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@softkit/exceptions

v0.1.5

Published

This library provides a set of general exceptions and interceptors for exceptions to follow the same structure based on [RFC7807](https://www.rfc-editor.org/rfc/rfc7807#section-3.1)

Downloads

74

Readme

Exceptions Library

This library provides a set of general exceptions and interceptors for exceptions to follow the same structure based on RFC7807

It can be used outside Softkit projects

Why we need it all?

  • To have a unified way to handle exceptions
  • To have ability to document exceptions properly in swagger
  • To have a unified way to handle exceptions on client side
  • To have a unified way to handle exceptions on server side and even proxy them to client side if you call internal service
  • To have a unified way to handle exceptions in logs
  • To have a unified way to understand what is a real exception and what is a business logic error. This allows to create an efficient and proactive support for customers.

Installation

yarn add @softkit/exceptions

You can also use @softkit/bootstrap to bootstrap your app with all default interceptors and filters.

This library is also tight to nestjs-i18n, this allows us to easily change default messaging for the library or if you are ok with what we have just use default (only english is available)

Usage

Default interceptors

  • AnyExceptionFilter - will catch any exception and return http status 500
  • HttpExceptionFilter - will catch any exception which is instance of AbstractHttpException and return http status from exception
  • ForbiddenExceptionFilter - will catch NestJS ForbiddenException and return http status 403, but with our RFC format
  • NotFoundExceptionFilter - will catch NestJS NotFoundException and return http status 404, but with our RFC format

Available exceptions

You can create your own exception it will be handled by default interceptor, and returned in a unified format. See ErrorResponse class.

import { AbstractHttpException } from '@softkit/exceptions';

export class YourException extends AbstractHttpException {
  constructor(rootCause?: unknown) {
    super(
      i18nString('exception.YOUR_EXCEPTION.TITLE'),
      i18nString('exception.YOUR_EXCEPTION.GENERAL_DETAIL'),
      HttpStatus.FORBIDDEN,
      undefined,
      rootCause,
    );
  }
}

Override wording

To override the default titles and details, you can take a localisation exception.json file from this library and inject it to your project

Load it with nestjs-i18n and substitution will be done automatically

You can also package this file to your localisation library to distribute across your organisation.

exception.json file is packaged to this repo and need to referenced and loadded in your app

if you won't load it you will see default keys for i18n