2.0.6 • Published 5 years ago

@altizure/errorcode v2.0.6

Weekly downloads
21
License
MIT
Repository
-
Last release
5 years ago

Install

yarn add @altizure/errorcode

Usage in front-end (see @ald/ui for more)

import { App, withData } from '../src'
import { Card, Flex, Pre, Text } from 'rebass'
import React, { Component } from 'react'

import { init } from '@altizure/errorcode'
import DocsHeader from '../docs/docs-header'
import PropTypes from 'prop-types'
import { contentWidth } from '../src/lib/theme'
import withi18nSSR from '../src/lib/with-i18n-ssr'

// mock data for demo
// this object is returned by API
//
const mockData = {
  error: true,
  errorCode: [
    "ERROR_TEXTURE_CROSSTILE",
    'ERROR_CAMINFO_CAMINTRINSICFILE_EMPTY_FILE',
    'ERROR_UNKNOWN'
  ],
  errorArgs: [
    {
      code: 'ERROR_CAMINFO_CAMINTRINSICFILE_EMPTY_FILE',
      description: ["DJI_0001.JPG;DJI_0002.JPG"],
      solution: null
    },
    {
      code: 'ERROR_UNKNOWN',
      description: ["buffer overflow"],
      solution: ["contact support@altizure.com", "try restarting computer"]
    }
  ]
}

@withi18nSSR()
class Report extends Component {
  static propTypes = {
    i18n: PropTypes.object
  }
  render () {
    const lang = langMap[this.props.i18n.lang]
    return mockData.error ? (
      mockData.errorCode.map((code, idx) => {
        const v2 = true
        if (v2) {
          // v2 usage, support dynamic info
          // backward compatible
          const {
            description: desc,
            solution: sol
          } = mockData.errorArgs && mockData.errorArgs.find(e => e.code === code) || {}
          const error = init({ lang, code, desc, sol })
          return (
            <div>
              <h1>{error.getCode()}</h1>
              <h2>{error.getDesc()}</h2>
              <h2>{error.getSol()}</h2>
            </div>
          )
        } else {
          // v1 usage, support only static error code
          return (
            <div>
              <h1>{ALL[lang][code].ErrorNumber}</h1>
              <h2>{ALL[lang][code].Description}</h2>
              <h2>{ALL[lang][code].Solution}</h2>
            </div>
          )
        }
    ) : (
      <div>
        <p>Project is All Good!</p>
      </div>
    )
  }
}

Usage in back-end

const en = require('@altizure/errorcode').en

app.get('/', (req, res) => {
    return res.end(en.ERROR_CAMINFO_EXIF_INVALID_IMAGESIZE.Description)
})
2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago