Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

my-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

my-error-handler

A simple little stupid library to personal purpose.

  • 1.0.6
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

my-error-handler



A simple little stupid library to personal purpose.

Don't mind.

The library helps to handle errors into API projects.



Instalation


npm i my-error-handler


Usage


throw


import { ErrorHandler, MyErrorHandler } from 'my-error-handler';

// Service
const fooService = (foo?: object) => {
  // code
  // condition ... 
  if (!foo){
    // Custom Error
    const customError: ErrorHandler = {
      message: "Not foo to process.",    
      error: {  // Optional                                
        code: 3256,
        others: {
          some: "foo"
        }
      }
    };

    const source: string = "./foo/foo.service";
    const detail: string = "Process foo in all intances";   // Optional

    // My Error Handler
    throw MyErrorHandler.throw(customError, source, detail);
  }  
  
  // more code
  return foo;
}


// Controller
const fooController = () => {
  try {
    fooService();
  } catch (error) {
    // My Error Handler 
    throw MyErrorHandler.throw(error, "/foo/foo.controller");
  }
}


// Caller
try {
  fooController();
} catch (error) {
  console.log("ERROR", error);
}


// Output
//
// ERROR {
//   message: 'Not foo to process.',
//   error: { 
//     code: 3256, 
//     others: { 
//       some: 'foo' 
//     } 
//   },
//   trace: {
//     source: '/user/foo.controller',
//     detail: '',
//     trace: {
//       source: './user/foo.service',
//       detail: 'Process foo in all intances',
//       trace: null
//     }
//   }
// }


throwError


import { ErrorHandler, MyErrorHandler } from 'my-error-handler';

// Service
const fooService = (foo?: object): Observable<unknown> => {
  // code
  // condition ... 
  if (!foo){
    // Custom Error
    const customError: ErrorHandler = {
      message: "Not foo to process.",    
      error: {  // Optional                                
        code: 3256,
        others: {
          some: "foo"
        }
      }
    };

    const source: string = "./foo/foo.service";
    const detail: string = "Process foo in all intances";   // Optional

    // My Error Handler
    return  MyErrorHandler.throwError(customError, source, detail);  }  
  
  // more code
  return createFoo$.pipe(
    ...
  );
}


// Controller
const fooController$ = (): Observable<unknown> => {
  // code
  return from(fooService()).pipe(
    // My Error Handler
    catchError((error: any) => MyErrorHandler.throwError(error, "/foo/foo.controller"))
  )
}



// Caller
fooController$().subscribe({
  next: (res: any) => console.log(res),
  error: (err: any) => console.log("ERROR", err)
})



// Output
//
// ERROR {
//   message: 'Not foo to process.',
//   error: { 
//     code: 3256, 
//     others: { 
//       some: 'foo' 
//     } 
//   },
//   trace: {
//     source: '/user/foo.controller',
//     detail: '',
//     trace: {
//       source: './user/foo.service',
//       detail: 'Process foo in all intances',
//       trace: null
//     }
//   }
// }


Keywords

FAQs

Package last updated on 03 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc