Skip to content

Commit a66e985

Browse files
authored
fix: forward errors (#5913)
Co-authored-by: drdelambre <drdelambre>
1 parent f2c733b commit a66e985

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

src/dataExplorer/components/FluxQueryBuilder.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export enum OverlayType {
4545

4646
const FluxQueryBuilder: FC = () => {
4747
const history = useHistory()
48-
const {hasChanged, query, vertical, setVertical} =
49-
useContext(PersistanceContext)
48+
const {hasChanged, vertical, setVertical} = useContext(PersistanceContext)
5049
const [overlayType, setOverlayType] = useState<OverlayType | null>(null)
5150
const [isOverlayVisible, setIsOverlayVisible] = useState(false)
5251
const {cancel} = useContext(QueryContext)
@@ -139,11 +138,6 @@ const FluxQueryBuilder: FC = () => {
139138
onClick={handleNewScript}
140139
text={isFlagEnabled('saveAsScript') ? 'New Script' : 'Clear'}
141140
icon={IconFont.Plus_New}
142-
status={
143-
query.length === 0
144-
? ComponentStatus.Disabled
145-
: ComponentStatus.Default
146-
}
147141
testID="flux-query-builder--new-script"
148142
/>
149143
{isFlagEnabled('saveAsScript') && (
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
.save-script-overlay__warning-text {
22
margin-bottom: 25px;
33
}
4+
5+
.save-script--error {
6+
display: block;
7+
margin: -10px 0 12px 0;
8+
}

src/dataExplorer/components/SaveAsScript.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {FC, useContext, useCallback, ChangeEvent} from 'react'
1+
import React, {FC, useContext, useCallback, ChangeEvent, useState} from 'react'
22
import {
33
Button,
44
ComponentColor,
@@ -38,6 +38,7 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
3838
useContext(PersistanceContext)
3939
const {cancel} = useContext(QueryContext)
4040
const {setStatus, setResult} = useContext(ResultsContext)
41+
const [error, setError] = useState<string>()
4142
const org = useSelector(getOrg)
4243

4344
const handleClose = () => {
@@ -89,21 +90,22 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
8990
}, [onClose, setStatus, setResult, cancel, history, org?.id])
9091

9192
const handleSaveScript = () => {
92-
try {
93-
save().then(() => {
93+
save()
94+
.then(() => {
95+
setError(null)
9496
dispatch(notify(scriptSaveSuccess(resource?.data?.name ?? '')))
97+
if (type !== OverlayType.OPEN) {
98+
onClose()
99+
}
100+
95101
if (type === OverlayType.NEW) {
96102
clear()
97103
}
98104
})
99-
} catch (error) {
100-
dispatch(notify(scriptSaveFail(resource?.data?.name ?? '')))
101-
console.error({error})
102-
} finally {
103-
if (type !== OverlayType.OPEN) {
104-
onClose()
105-
}
106-
}
105+
.catch(error => {
106+
dispatch(notify(scriptSaveFail(resource?.data?.name ?? '')))
107+
setError(error.message)
108+
})
107109
}
108110

109111
if (type == null) {
@@ -153,12 +155,13 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
153155
type={InputType.Text}
154156
value={resource?.data?.name}
155157
onChange={handleUpdateName}
156-
status={
157-
resource?.data?.id
158-
? ComponentStatus.Disabled
159-
: ComponentStatus.Default
160-
}
158+
status={error ? ComponentStatus.Error : ComponentStatus.Default}
161159
/>
160+
{error && (
161+
<div className="cf-form--element-error save-script--error">
162+
{error}
163+
</div>
164+
)}
162165
<InputLabel>Description</InputLabel>
163166
<Input
164167
name="description"
@@ -179,7 +182,7 @@ const SaveAsScript: FC<Props> = ({onClose, type}) => {
179182
<Button
180183
color={ComponentColor.Default}
181184
onClick={clear}
182-
text="No, Delete"
185+
text="No, Discard"
183186
testID="flux-query-builder--no-save"
184187
/>
185188
)}

src/dataExplorer/components/resources/types/script/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export default function script(register) {
5858
description: data.description,
5959
script: data.script,
6060
},
61-
}).then(() => {
61+
}).then(resp => {
62+
if (resp.status !== 201) {
63+
throw new Error(resp.data.message)
64+
}
65+
6266
return resource
6367
})
6468
}
@@ -71,17 +75,17 @@ export default function script(register) {
7175
language: 'flux',
7276
},
7377
}).then(resp => {
74-
if (resp.status === 201) {
75-
return {
76-
...resource,
77-
data: {
78-
...data,
79-
id: resp.data.id,
80-
},
81-
}
78+
if (resp.status !== 201) {
79+
throw new Error(resp.data.message)
8280
}
8381

84-
return resource
82+
return {
83+
...resource,
84+
data: {
85+
...data,
86+
id: resp.data.id,
87+
},
88+
}
8589
})
8690
},
8791
})

0 commit comments

Comments
 (0)