feat(ui): truncate error messages in toasts to 128 characters

This commit is contained in:
psychedelicious 2023-09-07 11:18:30 +10:00 committed by Kent Keirsey
parent 74cc409c72
commit 24d9357fdc

View File

@ -3,7 +3,7 @@ import { PayloadAction, createSlice, isAnyOf } from '@reduxjs/toolkit';
import { InvokeLogLevel } from 'app/logging/logger'; import { InvokeLogLevel } from 'app/logging/logger';
import { userInvoked } from 'app/store/actions'; import { userInvoked } from 'app/store/actions';
import { t } from 'i18next'; import { t } from 'i18next';
import { get, startCase, upperFirst } from 'lodash-es'; import { get, startCase, truncate, upperFirst } from 'lodash-es';
import { LogLevelName } from 'roarr'; import { LogLevelName } from 'roarr';
import { import {
isAnySessionRejected, isAnySessionRejected,
@ -357,10 +357,13 @@ export const systemSlice = createSlice({
result.data.error.detail.map((e) => { result.data.error.detail.map((e) => {
state.toastQueue.push( state.toastQueue.push(
makeToast({ makeToast({
title: upperFirst(e.msg), title: truncate(upperFirst(e.msg), { length: 128 }),
status: 'error', status: 'error',
description: `Path: description: truncate(
${e.loc.slice(3).join('.')}`, `Path:
${e.loc.join('.')}`,
{ length: 128 }
),
duration, duration,
}) })
); );
@ -375,7 +378,10 @@ export const systemSlice = createSlice({
makeToast({ makeToast({
title: t('toast.serverError'), title: t('toast.serverError'),
status: 'error', status: 'error',
description: get(errorDescription, 'detail', 'Unknown Error'), description: truncate(
get(errorDescription, 'detail', 'Unknown Error'),
{ length: 128 }
),
duration, duration,
}) })
); );