Skip to content

Commit 98c124d

Browse files
committed
chore: improve error notifications in annotations and notebooks (#6927)
* chore: improve error notifications in annotations and notebooks I noticed that annotations and notebooks could display the api error when requests fail - they are not consistent about it. * fix: improve failure error message notifications Including the underlying error in error messages, this improves notebooks, dashboards, labels, and annotations. Many other error notifications all need improving e.g. in tasks and secrets. * chore: run yarn prettier:fix * chore: whitespace to trigger ci
1 parent a977a9f commit 98c124d

File tree

10 files changed

+46
-35
lines changed

10 files changed

+46
-35
lines changed

src/annotations/components/annotationForm/AnnotationForm.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {useDispatch} from 'react-redux'
55
// Utils
66
import {event} from 'src/cloud/utils/reporting'
77
import classnames from 'classnames'
8+
import {getErrorMessage} from 'src/utils/api'
89

910
// Components
1011
import {
@@ -58,7 +59,8 @@ export const START_TIME_IN_FUTURE_MESSAGE = 'Start Time cannot be in the future'
5859

5960
/**
6061
* Form for editing and creating annotations.
61-
* It does support multi-line annotations, but the tradeoff is that the user cannot then press 'return' to submit the form.
62+
* It does support multi-line annotations, but the tradeoff is that the user
63+
* cannot then press 'return' to submit the form.
6264
* */
6365
export const AnnotationForm: FC<Props> = (props: Props) => {
6466
const [startTime, setStartTime] = useState(props.startTime)
@@ -129,7 +131,7 @@ export const AnnotationForm: FC<Props> = (props: Props) => {
129131
}
130132
}
131133

132-
const handleDelete = () => {
134+
const handleDelete = async () => {
133135
const editedAnnotation = {
134136
summary,
135137
startTime,
@@ -140,7 +142,7 @@ export const AnnotationForm: FC<Props> = (props: Props) => {
140142
}
141143

142144
try {
143-
dispatch(deleteAnnotations(editedAnnotation))
145+
await dispatch(deleteAnnotations(editedAnnotation))
144146
event(`annotations.delete_annotation.success`, {
145147
prefix: props.eventPrefix,
146148
})
@@ -150,7 +152,7 @@ export const AnnotationForm: FC<Props> = (props: Props) => {
150152
event(`annotations.delete_annotation.failure`, {
151153
prefix: props.eventPrefix,
152154
})
153-
dispatch(notify(deleteAnnotationFailed(err)))
155+
dispatch(notify(deleteAnnotationFailed(getErrorMessage(err))))
154156
}
155157
}
156158

src/dashboards/actions/thunks.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {setCloneName} from 'src/utils/naming'
5050
import {isLimitError} from 'src/cloud/utils/limits'
5151
import {getOrg} from 'src/organizations/selectors'
5252
import {getByID, getStatus} from 'src/resources/selectors'
53+
import {getErrorMessage} from 'src/utils/api'
5354

5455
// Constants
5556
import * as copy from 'src/shared/copy/notifications'
@@ -111,7 +112,7 @@ export const createDashboard =
111112
if (isLimitError(error)) {
112113
dispatch(notify(copy.resourceLimitReached('dashboards')))
113114
} else {
114-
dispatch(notify(copy.dashboardCreateFailed()))
115+
dispatch(notify(copy.dashboardCreateFailed(getErrorMessage(error))))
115116
}
116117
}
117118
}
@@ -199,7 +200,7 @@ export const cloneDashboard =
199200
if (isLimitError(error)) {
200201
dispatch(notify(copy.resourceLimitReached('dashboards')))
201202
} else {
202-
dispatch(notify(copy.dashboardCreateFailed()))
203+
dispatch(notify(copy.dashboardCreateFailed(getErrorMessage(error))))
203204
}
204205
}
205206
}
@@ -442,7 +443,7 @@ export const updateDashboard =
442443
dispatch(creators.editDashboard(updatedDashboard))
443444
} catch (error) {
444445
console.error(error)
445-
dispatch(notify(copy.dashboardUpdateFailed()))
446+
dispatch(notify(copy.dashboardUpdateFailed(getErrorMessage(error))))
446447
}
447448
}
448449

src/flows/context/api.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'src/client/notebooksRoutes'
1010
import {notebookUpdateFail} from 'src/shared/copy/notifications'
1111
import {notify} from 'src/shared/actions/notifications'
12+
import {getErrorMessage} from 'src/utils/api'
1213

1314
const DEFAULT_API_FLOW: PatchNotebookParams = {
1415
id: '',
@@ -99,10 +100,10 @@ export const migrateLocalFlowsToAPI = async (
99100
delete flows[localID]
100101
flows[id] = flow
101102
})
102-
).catch(() => {
103+
).catch(err => {
103104
// do not throw the error because some flows might have saved and we
104105
// need to save the new IDs to avoid creating duplicates next time.
105-
dispatch(notify(notebookUpdateFail()))
106+
dispatch(notify(notebookUpdateFail(getErrorMessage(err))))
106107
})
107108
}
108109
return flows

src/flows/context/flow.current.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import PageSpinner from 'src/perf/components/PageSpinner'
2424
import {pageTitleSuffixer} from 'src/shared/utils/pageTitles'
2525
import {RemoteDataState} from '@influxdata/clockface'
2626
import {setCloneName} from 'src/utils/naming'
27+
import {getErrorMessage} from 'src/utils/api'
2728

2829
const prettyid = customAlphabet('abcdefghijklmnop0123456789', 12)
2930

@@ -84,7 +85,7 @@ export const FlowProvider: FC = ({children}) => {
8485
dispatch(notify(notebookDeleteSuccess()))
8586
return id
8687
} catch (error) {
87-
dispatch(notify(notebookDeleteFail()))
88+
dispatch(notify(notebookDeleteFail(getErrorMessage(error))))
8889
}
8990
}, [dispatch, id])
9091

src/flows/context/flow.list.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from 'src/shared/copy/notifications'
3535
import {setCloneName} from 'src/utils/naming'
3636
import {CLOUD} from 'src/shared/constants'
37+
import {getErrorMessage} from 'src/utils/api'
3738

3839
export interface FlowListContextType extends FlowList {
3940
add: (flow?: Flow) => Promise<string | void>
@@ -238,8 +239,8 @@ export const FlowListProvider: FC = ({children}) => {
238239

239240
return flow.id
240241
})
241-
.catch(() => {
242-
dispatch(notify(notebookCreateFail()))
242+
.catch(err => {
243+
dispatch(notify(notebookCreateFail(getErrorMessage(err))))
243244
})
244245
}
245246

@@ -295,7 +296,7 @@ export const FlowListProvider: FC = ({children}) => {
295296
await deleteAPI({id})
296297
dispatch(notify(notebookDeleteSuccess()))
297298
} catch (error) {
298-
dispatch(notify(notebookDeleteFail()))
299+
dispatch(notify(notebookDeleteFail(getErrorMessage(error))))
299300
}
300301

301302
delete _flows[id]

src/flows/context/version.publish.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
publishNotebookSuccessful,
2828
} from 'src/shared/copy/notifications'
2929
import {event} from 'src/cloud/utils/reporting'
30+
import {getErrorMessage} from 'src/utils/api'
3031

3132
// Types
3233
import {RemoteDataState} from 'src/types'
@@ -103,7 +104,7 @@ export const VersionPublishProvider: FC = ({children}) => {
103104
setPublishLoading(RemoteDataState.Done)
104105
handleGetNotebookVersions()
105106
} catch (error) {
106-
dispatch(notify(publishNotebookFailed(flow.name)))
107+
dispatch(notify(publishNotebookFailed(flow.name, getErrorMessage(error))))
107108
setPublishLoading(RemoteDataState.Error)
108109
}
109110
}, [dispatch, handleGetNotebookVersions, flow.id, flow.name])

src/labels/actions/thunks.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import {getOrg} from 'src/organizations/selectors'
4343
import {viewableLabels} from 'src/labels/selectors'
4444
import {getStatus} from 'src/resources/selectors'
45+
import {getErrorMessage} from 'src/utils/api'
4546

4647
export const getLabels =
4748
() => async (dispatch: Dispatch<Action>, getState: GetState) => {
@@ -99,7 +100,7 @@ export const createLabel =
99100
dispatch(setLabel(resp.data.label.id, RemoteDataState.Done, label))
100101
} catch (error) {
101102
console.error(error)
102-
dispatch(notify(createLabelFailed()))
103+
dispatch(notify(createLabelFailed(getErrorMessage(error))))
103104
}
104105
}
105106

@@ -121,7 +122,7 @@ export const updateLabel =
121122
dispatch(setLabel(id, RemoteDataState.Done, label))
122123
} catch (error) {
123124
console.error(error)
124-
dispatch(notify(updateLabelFailed()))
125+
dispatch(notify(updateLabelFailed(getErrorMessage(error))))
125126
}
126127
}
127128

@@ -137,6 +138,6 @@ export const deleteLabel =
137138
dispatch(removeLabel(id))
138139
} catch (error) {
139140
console.error(error)
140-
dispatch(notify(deleteLabelFailed()))
141+
dispatch(notify(deleteLabelFailed(getErrorMessage(error))))
141142
}
142143
}

src/shared/copy/notifications/categories/dashboard.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const dashboardsGetFailed = (error: string): Notification => ({
2323
message: `Failed to retrieve dashboards: ${error}`,
2424
})
2525

26-
export const dashboardUpdateFailed = (): Notification => ({
26+
export const dashboardUpdateFailed = (error: string): Notification => ({
2727
...defaultErrorNotification,
2828
icon: IconFont.DashH,
29-
message: 'Could not update dashboard',
29+
message: `Could not update dashboard: ${error}`,
3030
})
3131

3232
export const dashboardDeleted = (name: string): Notification => ({
@@ -35,9 +35,9 @@ export const dashboardDeleted = (name: string): Notification => ({
3535
message: `Dashboard ${name} deleted successfully.`,
3636
})
3737

38-
export const dashboardCreateFailed = () => ({
38+
export const dashboardCreateFailed = (error: string) => ({
3939
...defaultErrorNotification,
40-
message: 'Failed to create dashboard.',
40+
message: `Failed to create dashboard: ${error}`,
4141
})
4242

4343
export const dashboardCreateSuccess = () => ({

src/shared/copy/notifications/categories/notebooks.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ export const panelCopyLinkFail = (): Notification => ({
2121
message: `Failed to copy the panel link`,
2222
})
2323

24-
export const notebookCreateFail = (): Notification => ({
24+
export const notebookCreateFail = (error: string): Notification => ({
2525
...defaultErrorNotification,
26-
message: `Failed to create Notebook, please try again.`,
26+
message: `Failed to create Notebook: ${error}`,
2727
})
2828

29-
export const notebookUpdateFail = (): Notification => ({
29+
export const notebookUpdateFail = (error: string): Notification => ({
3030
...defaultErrorNotification,
31-
message: `Failed to save changes to Notebook, please try again.`,
31+
message: `Failed to save changes to Notebook: ${error}`,
3232
})
3333

34-
export const notebookDeleteFail = (): Notification => ({
34+
export const notebookDeleteFail = (error: string): Notification => ({
3535
...defaultErrorNotification,
36-
message: `Failed to delete Notebook, please try again.`,
36+
message: `Failed to delete Notebook: ${error}`,
3737
})
3838

3939
export const notebookDeleteSuccess = (): Notification => ({
@@ -58,7 +58,10 @@ export const publishNotebookSuccessful = (name: string): Notification => ({
5858
message: `Successfully saved this version to ${name}'s version history.`,
5959
})
6060

61-
export const publishNotebookFailed = (name: string): Notification => ({
61+
export const publishNotebookFailed = (
62+
name: string,
63+
error: string
64+
): Notification => ({
6265
...defaultErrorNotification,
63-
message: `Failed to save this version to ${name}'s version history`,
66+
message: `Failed to save this version to ${name}'s version history: ${error}`,
6467
})

src/shared/copy/notifications/categories/tasks.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ export const getLabelsFailed = (): Notification => ({
2323
message: 'Failed to fetch labels',
2424
})
2525

26-
export const createLabelFailed = (): Notification => ({
26+
export const createLabelFailed = (error: string): Notification => ({
2727
...defaultErrorNotification,
28-
message: 'Failed to create label',
28+
message: `Failed to create label: ${error}`,
2929
})
3030

31-
export const updateLabelFailed = (): Notification => ({
31+
export const updateLabelFailed = (error: string): Notification => ({
3232
...defaultErrorNotification,
33-
message: 'Failed to update label',
33+
message: `Failed to update label: ${error}`,
3434
})
3535

36-
export const deleteLabelFailed = (): Notification => ({
36+
export const deleteLabelFailed = (error: string): Notification => ({
3737
...defaultErrorNotification,
38-
message: 'Failed to delete label',
38+
message: `Failed to delete label: ${error}`,
3939
})
4040

4141
export const taskNotCreated = (additionalMessage: string): Notification => ({

0 commit comments

Comments
 (0)