Skip to content

Commit 15f9577

Browse files
authored
feat: Add rejectNetworkError to calls (part three) (#3767)
1 parent 51d4fd5 commit 15f9577

27 files changed

+383
-563
lines changed

src/pages/RepoPage/RepoPage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ describe('RepoPage', () => {
290290
const { queryClient } = setup({ hasRepoData: false })
291291
render(<RepoPage />, { wrapper: wrapper({ queryClient }) })
292292

293-
const notFound = await screen.findByText(/not found/i)
294-
expect(notFound).toBeInTheDocument()
293+
const badRequest = await screen.findByText(/bad request/i)
294+
expect(badRequest).toBeInTheDocument()
295295
})
296296
})
297297

src/services/pull/usePullBundleComparisonList.test.tsx

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,19 @@ const mockPullBundleListData = {
1818
name: 'bundle.js',
1919
changeType: 'added',
2020
bundleChange: {
21-
loadTime: {
22-
threeG: 3,
23-
},
24-
size: {
25-
uncompress: 1,
26-
},
27-
},
28-
bundleData: {
29-
loadTime: {
30-
threeG: 4,
31-
},
32-
size: {
33-
uncompress: 2,
34-
},
21+
loadTime: { threeG: 3 },
22+
size: { uncompress: 1 },
3523
},
24+
bundleData: { loadTime: { threeG: 4 }, size: { uncompress: 2 } },
3625
},
3726
{
3827
name: 'bundle.css',
3928
changeType: 'removed',
4029
bundleChange: {
41-
loadTime: {
42-
threeG: 7,
43-
},
44-
size: {
45-
uncompress: 5,
46-
},
47-
},
48-
bundleData: {
49-
loadTime: {
50-
threeG: 8,
51-
},
52-
size: {
53-
uncompress: 6,
54-
},
30+
loadTime: { threeG: 7 },
31+
size: { uncompress: 5 },
5532
},
33+
bundleData: { loadTime: { threeG: 8 }, size: { uncompress: 6 } },
5634
},
5735
],
5836
},
@@ -165,40 +143,24 @@ describe('usePullBundleComparisonList', () => {
165143
name: 'bundle.js',
166144
changeType: 'added',
167145
bundleChange: {
168-
loadTime: {
169-
threeG: 3,
170-
},
171-
size: {
172-
uncompress: 1,
173-
},
146+
loadTime: { threeG: 3 },
147+
size: { uncompress: 1 },
174148
},
175149
bundleData: {
176-
loadTime: {
177-
threeG: 4,
178-
},
179-
size: {
180-
uncompress: 2,
181-
},
150+
loadTime: { threeG: 4 },
151+
size: { uncompress: 2 },
182152
},
183153
},
184154
{
185155
name: 'bundle.css',
186156
changeType: 'removed',
187157
bundleChange: {
188-
loadTime: {
189-
threeG: 7,
190-
},
191-
size: {
192-
uncompress: 5,
193-
},
158+
loadTime: { threeG: 7 },
159+
size: { uncompress: 5 },
194160
},
195161
bundleData: {
196-
loadTime: {
197-
threeG: 8,
198-
},
199-
size: {
200-
uncompress: 6,
201-
},
162+
loadTime: { threeG: 8 },
163+
size: { uncompress: 6 },
202164
},
203165
},
204166
],
@@ -242,7 +204,7 @@ describe('usePullBundleComparisonList', () => {
242204
consoleSpy.mockRestore()
243205
})
244206

245-
it('throws a 404', async () => {
207+
it('throws a 400', async () => {
246208
setup({ isUnsuccessfulParseError: true })
247209
const { result } = renderHook(
248210
() =>
@@ -259,8 +221,8 @@ describe('usePullBundleComparisonList', () => {
259221
await waitFor(() =>
260222
expect(result.current.error).toEqual(
261223
expect.objectContaining({
262-
status: 404,
263-
data: null,
224+
dev: 'usePullBundleComparisonList - Parsing Error',
225+
status: 400,
264226
})
265227
)
266228
)
@@ -294,8 +256,8 @@ describe('usePullBundleComparisonList', () => {
294256
await waitFor(() =>
295257
expect(result.current.error).toEqual(
296258
expect.objectContaining({
259+
dev: 'usePullBundleComparisonList - Not Found Error',
297260
status: 404,
298-
data: {},
299261
})
300262
)
301263
)
@@ -329,6 +291,7 @@ describe('usePullBundleComparisonList', () => {
329291
await waitFor(() =>
330292
expect(result.current.error).toEqual(
331293
expect.objectContaining({
294+
dev: 'usePullBundleComparisonList - Owner Not Activated',
332295
status: 403,
333296
})
334297
)

src/services/pull/usePullBundleComparisonList.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
RepoOwnerNotActivatedErrorSchema,
1212
} from 'services/repo/schemas'
1313
import Api from 'shared/api'
14+
import { rejectNetworkError } from 'shared/api/rejectNetworkError'
1415
import A from 'ui/A'
1516

1617
const BundleSchema = z.object({
@@ -160,24 +161,28 @@ export function usePullBundleComparisonList({
160161
const parsedRes = RequestSchema.safeParse(res?.data)
161162

162163
if (!parsedRes.success) {
163-
return Promise.reject({
164-
status: 404,
165-
data: null,
164+
return rejectNetworkError({
165+
errorName: 'Parsing Error',
166+
errorDetails: {
167+
callingFn: 'usePullBundleComparisonList',
168+
error: parsedRes.error,
169+
},
166170
})
167171
}
168172

169173
const data = parsedRes.data
170174

171175
if (data?.owner?.repository?.__typename === 'NotFoundError') {
172-
return Promise.reject({
173-
status: 404,
174-
data: {},
176+
return rejectNetworkError({
177+
errorName: 'Not Found Error',
178+
errorDetails: { callingFn: 'usePullBundleComparisonList' },
175179
})
176180
}
177181

178182
if (data?.owner?.repository?.__typename === 'OwnerNotActivatedError') {
179-
return Promise.reject({
180-
status: 403,
183+
return rejectNetworkError({
184+
errorName: 'Owner Not Activated',
185+
errorDetails: { callingFn: 'usePullBundleComparisonList' },
181186
data: {
182187
detail: (
183188
<p>

src/services/pull/usePullBundleHeadList.test.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ const mockOwnerNotActivated = {
7373

7474
const server = setupServer()
7575
const queryClient = new QueryClient({
76-
defaultOptions: {
77-
queries: {
78-
retry: false,
79-
},
80-
},
76+
defaultOptions: { queries: { retry: false } },
8177
})
8278

8379
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
@@ -225,6 +221,7 @@ describe('usePullBundleHeadList', () => {
225221
await waitFor(() =>
226222
expect(result.current.error).toEqual(
227223
expect.objectContaining({
224+
dev: 'usePullBundleHeadList - Not Found Error',
228225
status: 404,
229226
})
230227
)
@@ -259,6 +256,7 @@ describe('usePullBundleHeadList', () => {
259256
await waitFor(() =>
260257
expect(result.current.error).toEqual(
261258
expect.objectContaining({
259+
dev: 'usePullBundleHeadList - Owner Not Activated',
262260
status: 403,
263261
})
264262
)
@@ -276,7 +274,7 @@ describe('usePullBundleHeadList', () => {
276274
consoleSpy.mockRestore()
277275
})
278276

279-
it('throws a 404', async () => {
277+
it('throws a 400', async () => {
280278
setup({ isUnsuccessfulParseError: true })
281279
const { result } = renderHook(
282280
() =>
@@ -293,7 +291,8 @@ describe('usePullBundleHeadList', () => {
293291
await waitFor(() =>
294292
expect(result.current.error).toEqual(
295293
expect.objectContaining({
296-
status: 404,
294+
dev: 'usePullBundleHeadList - Parsing Error',
295+
status: 400,
297296
})
298297
)
299298
)

src/services/pull/usePullBundleHeadList.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
RepoOwnerNotActivatedErrorSchema,
77
} from 'services/repo/schemas'
88
import Api from 'shared/api'
9-
import { type NetworkErrorObject } from 'shared/api/helpers'
9+
import { rejectNetworkError } from 'shared/api/rejectNetworkError'
1010
import A from 'ui/A'
1111

1212
const BundleSchema = z.object({
@@ -132,26 +132,28 @@ export function usePullBundleHeadList({
132132
const parsedRes = RequestSchema.safeParse(res?.data)
133133

134134
if (!parsedRes.success) {
135-
return Promise.reject({
136-
status: 404,
137-
data: {},
138-
dev: `usePullBundleHeadList - 404 failed to parse`,
139-
} satisfies NetworkErrorObject)
135+
return rejectNetworkError({
136+
errorName: 'Parsing Error',
137+
errorDetails: {
138+
callingFn: 'usePullBundleHeadList',
139+
error: parsedRes.error,
140+
},
141+
})
140142
}
141143

142144
const data = parsedRes.data
143145

144146
if (data?.owner?.repository?.__typename === 'NotFoundError') {
145-
return Promise.reject({
146-
status: 404,
147-
data: {},
148-
dev: `usePullBundleHeadList - 404 NotFoundError`,
149-
} satisfies NetworkErrorObject)
147+
return rejectNetworkError({
148+
errorName: 'Not Found Error',
149+
errorDetails: { callingFn: 'usePullBundleHeadList' },
150+
})
150151
}
151152

152153
if (data?.owner?.repository?.__typename === 'OwnerNotActivatedError') {
153-
return Promise.reject({
154-
status: 403,
154+
return rejectNetworkError({
155+
errorName: 'Owner Not Activated',
156+
errorDetails: { callingFn: 'usePullBundleHeadList' },
155157
data: {
156158
detail: (
157159
<p>
@@ -162,8 +164,7 @@ export function usePullBundleHeadList({
162164
</p>
163165
),
164166
},
165-
dev: `usePullBundleHeadList - 404 OwnerNotActivatedError`,
166-
} satisfies NetworkErrorObject)
167+
})
167168
}
168169

169170
return {

src/services/pull/usePullCompareTotalsTeam.test.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ const mockUnsuccessfulParseError = {}
6161

6262
const server = setupServer()
6363
const queryClient = new QueryClient({
64-
defaultOptions: {
65-
queries: {
66-
retry: false,
67-
},
68-
},
64+
defaultOptions: { queries: { retry: false } },
6965
})
7066

7167
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
@@ -140,15 +136,11 @@ describe('usePullCompareTotalsTeam', () => {
140136
{
141137
headName: 'src/App.tsx',
142138
missesCount: 0,
143-
patchCoverage: {
144-
coverage: 100,
145-
},
139+
patchCoverage: { coverage: 100 },
146140
},
147141
],
148142
},
149-
patchTotals: {
150-
coverage: 100,
151-
},
143+
patchTotals: { coverage: 100 },
152144
state: 'processed',
153145
},
154146
}
@@ -205,8 +197,8 @@ describe('usePullCompareTotalsTeam', () => {
205197
await waitFor(() =>
206198
expect(result.current.error).toEqual(
207199
expect.objectContaining({
200+
dev: 'usePullCompareTotalsTeam - Not Found Error',
208201
status: 404,
209-
dev: 'usePullCompareTotalsTeam - 404 not found',
210202
})
211203
)
212204
)
@@ -240,8 +232,8 @@ describe('usePullCompareTotalsTeam', () => {
240232
await waitFor(() =>
241233
expect(result.current.error).toEqual(
242234
expect.objectContaining({
235+
dev: 'usePullCompareTotalsTeam - Owner Not Activated',
243236
status: 403,
244-
dev: 'usePullCompareTotalsTeam - 403 owner not activated',
245237
})
246238
)
247239
)
@@ -258,7 +250,7 @@ describe('usePullCompareTotalsTeam', () => {
258250
consoleSpy.mockRestore()
259251
})
260252

261-
it('throws a 404', async () => {
253+
it('throws a 400', async () => {
262254
setup({ isUnsuccessfulParseError: true })
263255
const { result } = renderHook(
264256
() =>
@@ -275,8 +267,8 @@ describe('usePullCompareTotalsTeam', () => {
275267
await waitFor(() =>
276268
expect(result.current.error).toEqual(
277269
expect.objectContaining({
278-
status: 404,
279-
dev: 'usePullCompareTotalsTeam - 404 failed to parse',
270+
dev: 'usePullCompareTotalsTeam - Parsing Error',
271+
status: 400,
280272
})
281273
)
282274
)

0 commit comments

Comments
 (0)