MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / toMessageProps

Function toMessageProps

pkg/webui/lib/errors/utils.js:484–563  ·  view source on GitHub ↗
(error, each = false)

Source from the content-addressed store, hash-verified

482 * @returns {object|Array} Message props of the error object, or generic error object.
483 */
484export const toMessageProps = (error, each = false) => {
485 const props = []
486
487 // Check if it is an error message and transform it to a intl message.
488 if (isBackendErrorDetails(error) || isBackend(error)) {
489 const pathErrors = getBackendErrorDetailsPathError(error)
490 let errorDetails
491
492 if (
493 (hasValidDetails(error) && isBackendErrorDetails(error.details[0])) ||
494 isBackendErrorDetails(error)
495 ) {
496 if (isBackendErrorDetails(pathErrors)) {
497 errorDetails = pathErrors
498 } else if ('details' in error && isBackendErrorDetails(error.details[0])) {
499 errorDetails = error.details[0]
500 } else {
501 errorDetails = error
502 }
503
504 if (hasCauses(errorDetails)) {
505 // Use the root cause if any.
506 const rootCause = getBackendErrorRootCause(errorDetails)
507
508 // If the attributes are missing values, use the generated default values based on the message.
509 const messageValues = rootCause?.message_format?.match(/[^{}]+(?=})/g) || []
510 const values = messageValues.reduce(
511 (obj, val) => {
512 if (!(val in obj)) {
513 obj[val] = `{${val}}`
514 }
515
516 return obj
517 },
518 { ...rootCause.attributes },
519 )
520
521 props.push({
522 content: {
523 id: getBackendErrorDetailsId(rootCause),
524 defaultMessage: rootCause.message_format,
525 },
526 values,
527 })
528 }
529
530 props.push({
531 content: {
532 id: getBackendErrorDetailsId(errorDetails),
533 defaultMessage: errorDetails.message_format,
534 },
535 values: errorDetails.attributes,
536 })
537 } else {
538 props.push({
539 content: {
540 id: getBackendErrorId(error),
541 defaultMessage: getBackendErrorDefaultMessage(error),

Callers 4

index.jsFile · 0.90
index.jsFile · 0.90
index.jsFile · 0.90
utils_test.jsFile · 0.90

Calls 14

isBackendErrorDetailsFunction · 0.85
isBackendFunction · 0.85
hasValidDetailsFunction · 0.85
hasCausesFunction · 0.85
getBackendErrorRootCauseFunction · 0.85
getBackendErrorDetailsIdFunction · 0.85
getBackendErrorIdFunction · 0.85
isFrontendFunction · 0.85
isTranslatedFunction · 0.85
isConnectionFailureErrorFunction · 0.85

Tested by

no test coverage detected