@altizure/errorcode
v2.0.6
Published
i18n of error code
Downloads
48
Readme
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 [email protected]", "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)
})