Skip to content

Commit 776612f

Browse files
author
Gene Hynson
authored
feat(sub): show 400 errors to user (#5237)
1 parent 3269fb7 commit 776612f

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import {Notification} from 'src/types'
22
import {defaultErrorNotification} from 'src/shared/copy/notifications'
33

4-
// Subscriptions
5-
export const subscriptionCreateFail = (): Notification => ({
4+
export const subscriptionCreateFail = (message?: string): Notification => ({
65
...defaultErrorNotification,
7-
message: `Failed to create Subscription, please try again.`,
6+
message: message ?? `Failed to create Subscription, please try again.`,
87
})
98

10-
export const subscriptionUpdateFail = (): Notification => ({
9+
export const subscriptionUpdateFail = (message?: string): Notification => ({
1110
...defaultErrorNotification,
12-
message: `Failed to update Subscription, please try again.`,
11+
message: message ?? `Failed to update Subscription, please try again.`,
1312
})
1413

15-
export const subscriptionStatusUpdateFail = (): Notification => ({
14+
export const subscriptionStatusUpdateFail = (
15+
message?: string
16+
): Notification => ({
1617
...defaultErrorNotification,
17-
message: `Failed to update Subscription status, please try again.`,
18+
message: message ?? `Failed to update Subscription status, please try again.`,
1819
})
1920

2021
export const subscriptionsGetFail = (): Notification => ({

src/writeData/subscriptions/context/api.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,46 +43,54 @@ if (CLOUD) {
4343

4444
export const createAPI = async (subscription: typeof PostBrokerSubParams) => {
4545
const res = await postBrokerSub(subscription)
46-
if (res.status != 201) {
46+
if (res.status === 400) {
47+
// 400s contain an err with info for the user
4748
throw new Error(res.data.message)
4849
}
50+
if (res.status !== 201) {
51+
throw new Error()
52+
}
4953
}
5054

5155
export const updateAPI = async (subscription: typeof PutBrokerSubParams) => {
5256
const res = await putBrokerSub(subscription)
53-
if (res.status != 200) {
57+
if (res.status === 400) {
58+
// 400s contain an err with info for the user
5459
throw new Error(res.data.message)
5560
}
61+
if (res.status !== 200) {
62+
throw new Error()
63+
}
5664
return res.data
5765
}
5866

5967
export const deleteAPI = async (id: typeof DeleteBrokerSubParams) => {
6068
const res = await deleteBrokerSub({id})
61-
if (res.status != 204) {
62-
throw new Error(res.data.message)
69+
if (res.status !== 204) {
70+
throw new Error()
6371
}
6472
}
6573

6674
export const getAllAPI = async () => {
6775
const res = await getBrokerSubs()
68-
if (res.status != 200) {
69-
throw new Error(res.data.message)
76+
if (res.status !== 200) {
77+
throw new Error()
7078
}
7179
return res.data
7280
}
7381

7482
export const getByIDAPI = async (id: typeof GetBrokerSubParams) => {
7583
const res = await getBrokerSub(id)
76-
if (res.status != 200) {
77-
throw new Error(res.data.message)
84+
if (res.status !== 200) {
85+
throw new Error()
7886
}
7987
return res.data
8088
}
8189

8290
export const getStatusAPI = async (id: typeof GetBrokerSubsStatusParams) => {
8391
const res = await getBrokerSubsStatus(id)
84-
if (res.status != 200) {
85-
throw new Error(res.data.message)
92+
if (res.status !== 200) {
93+
throw new Error()
8694
}
8795
return res.data
8896
}
@@ -91,16 +99,20 @@ export const updateStatusAPI = async (
9199
status: typeof PutBrokerSubsStatusParams
92100
) => {
93101
const res = await putBrokerSubsStatus(status)
94-
if (res.status != 200) {
102+
if (res.status === 400) {
103+
// 400s contain an err with info for the user
95104
throw new Error(res.data.message)
96105
}
106+
if (res.status !== 200) {
107+
throw new Error()
108+
}
97109
return res.data
98110
}
99111

100112
export const getAllStatuses = async () => {
101113
const res = await getBrokerSubsStatuses()
102114
if (res.status !== 200) {
103-
throw new Error(res.data.message)
115+
throw new Error()
104116
}
105117

106118
return res.data

src/writeData/subscriptions/context/subscription.create.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export const SubscriptionCreateProvider: FC = ({children}) => {
9696
setLoading(RemoteDataState.Done)
9797
history.push(`/orgs/${org.id}/${LOAD_DATA}/${SUBSCRIPTIONS}`)
9898
})
99-
.catch(() => {
99+
.catch(err => {
100100
setLoading(RemoteDataState.Done)
101-
dispatch(notify(subscriptionCreateFail()))
101+
dispatch(notify(subscriptionCreateFail(err.message)))
102102
})
103103
}
104104

src/writeData/subscriptions/context/subscription.update.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ export const SubscriptionUpdateProvider: FC = ({children}) => {
130130
setLoading(RemoteDataState.Done)
131131
history.push(`/orgs/${org.id}/${LOAD_DATA}/${SUBSCRIPTIONS}`)
132132
})
133-
.catch(() => {
133+
.catch(err => {
134134
setLoading(RemoteDataState.Done)
135-
dispatch(notify(subscriptionUpdateFail()))
135+
dispatch(notify(subscriptionUpdateFail(err.message)))
136136
})
137137
}
138138

@@ -158,9 +158,9 @@ export const SubscriptionUpdateProvider: FC = ({children}) => {
158158
.then(() => {
159159
getSubscription()
160160
})
161-
.catch(() => {
161+
.catch(err => {
162162
setLoading(RemoteDataState.Done)
163-
dispatch(notify(subscriptionStatusUpdateFail()))
163+
dispatch(notify(subscriptionStatusUpdateFail(err.message)))
164164
})
165165
}
166166

0 commit comments

Comments
 (0)