New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@altizure/errorcode

Package Overview
Dependencies
Maintainers
4
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@altizure/errorcode

i18n of error code

latest
npmnpm
Version
2.0.6
Version published
Maintainers
4
Created
Source

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)
})

FAQs

Package last updated on 02 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts