catch-err-msg
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

catch-err-msg

Build Status MEAN Module npm version Node.js Version

Helper function to extract error message for TypeScript 4.4+ catch clause.

import errMsg from 'catch-err-msg';

try {
  // ...
} catch (err) {
  // err: unknown in TypeScript 4.4+
  const message = errMsg(err);
  console.error(message);
}

Source

export default function errMsg(err: any): string {
  return err?.message ? `${err.message}` : `${err}`;
}

Readme

Keywords

none

Package Sidebar

Install

npm i catch-err-msg

Weekly Downloads

28

Version

1.0.0

License

MIT

Unpacked Size

3.62 kB

Total Files

6

Last publish

Collaborators

  • mgenware