lodash#isError TypeScript Examples

The following examples show how to use lodash#isError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: download.ts    From generator-earth with MIT License 6 votes vote down vote up
download: IDownload = (url, params, type = 'get') => new Promise(async (resolve, reject) => {
    try {
        const res = await request[type](url, params)

        // 请求出错,比如:状态码值404情况
        if (isError(res)) {
            throw new Error(`系统异常,请求失败\n错误信息:${res.message || ''}`)
        }
        // 如果返回的是json,则说明导出失败
        if ('code' in res) {
            throw new Error(`导出失败\n错误码值:${res.code}\n错误信息:${res.msg || ''}`)
        }

        // 获取文件名
        const filename = res.headers.get('Content-Disposition').match(/filename=(.*)/) || []
        const blob = await res.blob()

        const fileUrl = URL.createObjectURL(blob)
        resolve()

        const a = document.createElement('a')
        a.href = fileUrl
        a.download = decodeURIComponent(filename[1] || '文件.zip').trim()
        a.click()
        window.URL.revokeObjectURL(fileUrl)
    } catch (e) {
        reject(e)
    }
})
Example #2
Source File: showError.tsx    From generator-earth with MIT License 6 votes vote down vote up
showError = (e?: Error | string): void => {
    let msg;

    if (isError(e)) {
        msg = e.message
    } else if (isString(e)) {
        msg = e;
    }

    msg = msg || '系统异常'

    Modal.error({
        title: '错误提示',
        content: <pre>{msg}</pre>,
    })
}
Example #3
Source File: limiterGroup.ts    From ts-di-starter with MIT License 6 votes vote down vote up
/**
   * Handle rejection from limiter
   *
   * @param {Error|RateLimiterRes} error
   * @returns {RateLimiterRes}
   */
  static handleRejection(error): RateLimiterRes {
    if (isError(error)) {
      throw error;
    }

    return error;
  }