i18n of error code
npm install @altizure/errorcode
#### Install
``bash`
yarn add @altizure/errorcode`
#### Usage in front-end (see @ald/ui for more)javascript
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 (
Project is All Good!
#### Usage in back-end
`javascript
const en = require('@altizure/errorcode').enapp.get('/', (req, res) => {
return res.end(en.ERROR_CAMINFO_EXIF_INVALID_IMAGESIZE.Description)
})
``