项目原始demo,不改动
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # loud-rejection [![Build Status](https://travis-ci.org/sindresorhus/loud-rejection.svg?branch=master)](https://travis-ci.org/sindresorhus/loud-rejection) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/loud-rejection/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/loud-rejection?branch=master)
  2. > Make unhandled promise rejections fail loudly instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2)
  3. By default, promises fail silently if you don't attach a `.catch()` handler to them.
  4. Use this in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**<br>
  5. Not needed in the browser as unhandled promises are shown in the console.
  6. ## Install
  7. ```
  8. $ npm install --save loud-rejection
  9. ```
  10. ## Usage
  11. ```js
  12. const loudRejection = require('loud-rejection');
  13. const promiseFn = require('promise-fn');
  14. // Install the unhandledRejection listeners
  15. loudRejection();
  16. promiseFn();
  17. ```
  18. Without this module it's more verbose and you might even miss some that will fail silently:
  19. ```js
  20. const promiseFn = require('promise-fn');
  21. function error(err) {
  22. console.error(err.stack);
  23. process.exit(1);
  24. }
  25. promiseFn().catch(error);
  26. ```
  27. ### Register script
  28. Alternatively to the above, you may simply require `loud-rejection/register` and the unhandledRejection listener will be automagically installed for you.
  29. This is handy for ES2015 imports:
  30. ```js
  31. import 'loud-rejection/register';
  32. ```
  33. ## API
  34. ### loudRejection([log])
  35. #### log
  36. Type: `Function`<br>
  37. Default: `console.error`
  38. Custom logging function to print the rejected promise. Receives the error stack.
  39. ## License
  40. MIT © [Sindre Sorhus](https://sindresorhus.com)