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

@alicloud/console-base-error-prompt

v1.11.9

Published

ConsoleBase 错误弹窗器

Downloads

1,221

Readme

@alicloud/console-base-error-prompt

TODO see in action

@alicloud/error-prompt 的进化版,不再依赖 wind 和 fusion,也不需要手动引样式和指定语言,更不再是一个工厂。

使用

一般用法

import errorPrompt from '@alicloud/console-base-error-prompt';

errorPrompt(error/*, extra*/);

error 可以是以下类型:

  • undefined | null 将被忽略
  • 字符串
  • JSX
  • plain 对象
  • 扩展了的 Error 实例对象

如果 error 是对象,除了标准属性 message 之外,可以附加 code、requestId,同时可以有 details 属性,长这样:

interface IErrorDetails {
  url?: string;
  method?: string;
  params?: string | Record<string, unkonwn>;
  body?: string | Record<string, unkonwn>;
}

自定义标题、按钮

有的时候,会根据 code 可能需要调整 titlebutton

errorPrompt(error, {
  button,
  title
});

// 或
errorPrompt(error, ({ // 这里是解析后的对象,保证存在,但不保证有 code
  code
}) => {
  if (code === 'ConsoleNeedLogin') {
    return {
      title: '你妹登录 - 需要国际化',
      button: {
        href: '/',
        target: '_blank',
        label: '登录 - 需要国际化'
      }
    };
  }
});

如何忽略错误

所谓「忽略」错误,是指虽然被接收,但不会弹窗。

虽然可以用 null | undefined,是的,在 JS 中 null | undefined 是可以被当成错误的存在,但这并不是推荐的做法。

这种场景下,可以利用帮助方法 createErrorToIgnore throw 一个新错误,这个错误一定会被忽略。

import {
  createErrorToIgnore
} from '@alicloud/console-base-error-prompt';

try {
  doMyStuff();
} catch (err) {
  // 可以忽略该错误,或错误在业务层已经被处理
  if (canIgnoreError(err)) {
    throw createErrorToIgnore();
  }
}