diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-12-20 10:45:02 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-12-20 10:45:02 -0600 |
| commit | efed2c34a9266a58e8b729d60b0ae55278a7f779 (patch) | |
| tree | 74176ac5ae082b96c1e2a62811a2a03a554e5075 /src | |
| parent | 51d7c419fca778287d9a2510828eb66f0424777f (diff) | |
| download | slskd-efed2c34a9266a58e8b729d60b0ae55278a7f779.tar.gz | |
gracefully handle errors updating config
Diffstat (limited to 'src')
| -rw-r--r-- | src/web/src/components/System/Options/Edit.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js index a68b6fcf..54c0131f 100644 --- a/src/web/src/components/System/Options/Edit.js +++ b/src/web/src/components/System/Options/Edit.js @@ -10,6 +10,7 @@ const Edit = ({ cancelAction }) => { const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); const [yamlError, setYamlError] = useState(); + const [updateError, setUpdateError] = useState(); useEffect(() => { get(); @@ -42,8 +43,13 @@ const Edit = ({ cancelAction }) => { await validate(yaml); if (!yamlError) { - await updateYaml({ yaml }); - cancelAction(); + try { + await updateYaml({ yaml }); + cancelAction(); + } + catch (error) { + setUpdateError(error.response.data); + } } } @@ -61,14 +67,14 @@ const Edit = ({ cancelAction }) => { <Icon name='warning sign'/>Editing {location} </Message> <div - {...{ className: yamlError ? 'edit-code-container-error' : 'edit-code-container' }} + {...{ className: (yamlError || updateError) ? 'edit-code-container-error' : 'edit-code-container' }} > <CodeEditor value={yaml} onChange={(value) => update(value)} /> </div> - {yamlError && <Message className='no-grow' negative><Icon name='x'/>{yamlError}</Message>} + {(yamlError || updateError) && <Message className='no-grow' negative><Icon name='x'/>{(yamlError ?? '') + (updateError ?? '')}</Message>} <div className='footer-buttons'> <Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button> <Button negative onClick={() => cancelAction()}><Icon name='close'/>Cancel</Button> |
