All error messages in german and in englisch

This commit is contained in:
rxf
2023-05-09 15:37:27 +02:00
parent 2cf418756d
commit 347c6bdc96
17 changed files with 1007 additions and 243 deletions
+4 -5
View File
@@ -1,21 +1,20 @@
// parse the params from http call
import * as ERR from '../utilities/errortexts.js'
import {returnOnError} from "./reporterror.js"
const checkParams = (params, mo) => {
let o = {opts: {}, err: null}
if ((mo.mandatory.length !== 0) && (params === undefined)) {
return returnOnError(o, ERR.NOPARAMETER, checkParams.name )
return returnOnError(o, 'NOPARAMETER', checkParams.name )
}
for (let p of mo.mandatory) {
if (!(p.name in params)) {
return returnOnError(o, ERR.NOMANDPARAM.replace('xx', p.name), checkParams.name )
return returnOnError(o, 'NOMANDPARAM', checkParams.name, p.name)
}
if (p.type === 'int') {
let x = parseInt(params[p.name])
if (isNaN(x)) {
return returnOnError(o, ERR.PARAMNONUM, checkParams.name )
return returnOnError(o, 'PARAMNONUM', checkParams.name, p.name)
} else {
o.opts[p.name] = x
continue
@@ -23,7 +22,7 @@ const checkParams = (params, mo) => {
} else if (p.type === 'float') {
let x = parseFloat(params[p.name])
if (isNaN(x)) {
return returnOnError(o, ERR.PARAMNONUM, checkParams.name )
return returnOnError(o, 'PARAMNONUM', checkParams.name, p.name)
} else {
o.opts[p.name] = x
continue
-16
View File
@@ -1,16 +0,0 @@
// Errortexts
export const CMNDUNKOWN = 'Command not known'
export const NOTHIMG = 'Nothing to show'
export const PARAMNONUM = `Parameter ${'xx'} is not a number`
export const NOTYP = 'No type given'
export const NOSENSFOUND = 'No suitable sensors found in properties'
export const NOMANDPARAM = `Mandatory parameter '${'xx'}' not given`
export const NOPROPSREAD = `No properties read for sensor ${'xx'}`
export const NOPARAMETER = 'No parameter given'
export const RESPSTATUS = `Returned status = ${'xx'}`
export const NODATA = 'No data found'
export const SYNTAXURL = 'Syntax error in calling url!'
export const WRONGTYPE = `Sensor ${'xx'} is not of type ${'yy'}`
export const NOLASTDATES = `Problems fetching last dates from database`
export const NOPROPSFOUND = `Properties collection not found`
+9 -1
View File
@@ -1,4 +1,5 @@
import {logit} from "./logit.js";
import { translate as trans } from '../routes/api.js'
export const reportError = (message, errortext) => {
message.error = true
@@ -6,7 +7,14 @@ export const reportError = (message, errortext) => {
return message
}
export const returnOnError = (pr, error, name) => {
export const returnOnError = (pr, error, name, p1='', p2='') => {
error = trans(error)
if (error.indexOf('xxx') !== -1) {
error = error.replace('xxx', p1)
}
if (error.indexOf('yyy') !== -1) {
error = error.replace('yyy', p1)
}
pr.err = error
logit(`${name}: ${error}`)
return pr