Skip to content

Commit b9b23dc

Browse files
authored
Merge pull request #297 from scientist-softserv/295-better-error-handling
295 better error handling
2 parents 499a0e4 + 6bdc6e4 commit b9b23dc

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

pages/requests/[uuid].js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Request = ({ session }) => {
3333
* as a dynamically routed file, the router query will always consist of a "key: value" pair that's determined by the name of
3434
* the file (key) and path string (value). additional query properties may also exist if they were explicitly passed.
3535
*/
36-
const { uuid } = router.query
36+
const { createRequestError, uuid } = router.query
3737
const accessToken = session?.accessToken
3838
const { request, isLoadingRequest, isRequestError } = useOneRequest(uuid, accessToken)
3939
const { allSOWs, isLoadingSOWs, isSOWError } = useAllSOWs(uuid, request?.identifier, accessToken)
@@ -78,6 +78,33 @@ const Request = ({ session }) => {
7878
)
7979
}
8080

81+
// this error is a result of creating the request
82+
if (createRequestError) {
83+
// TODO(alishaevn): how to handle a "sent to vendor" error?
84+
const attachmentError = JSON.parse(createRequestError).config.url.includes('notes')
85+
86+
return (
87+
<Notice
88+
alert={attachmentError &&
89+
{
90+
body: ['Your attachment failed. Please visit your request and try again from the "View Files" tab.'],
91+
title: 'Attachment Error',
92+
variant: 'info',
93+
}
94+
}
95+
dismissible={false}
96+
withBackButton={true}
97+
buttonProps={attachmentError &&
98+
{
99+
onClick: () => router.push({ pathname: `/requests/${uuid}` }),
100+
text: 'Click to view your request.',
101+
}
102+
}
103+
/>
104+
)
105+
}
106+
107+
// this error is a result of getting the request or its related data
81108
if (isError) {
82109
return (
83110
<Notice

pages/requests/new/[ware].js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,34 @@ const NewRequest = ({ session }) => {
9999
wareID,
100100
accessToken,
101101
})
102-
if (error) return setCreateRequestError(error)
102+
// if we have data AND an error, the request was created, but the attachments failed
103+
// in that case, we still need to send the request to the vendor
104+
if (error && !data) {
105+
setFormSubmitting(false)
106+
setCreateRequestError(error)
107+
return
108+
} else if (error) {
109+
setCreateRequestError(error)
110+
}
103111

104112
const sentToVendor = await sendRequestToVendor(data.id, accessToken)
105-
if (sentToVendor.error) return setCreateRequestError(sentToVendor.error)
113+
if (sentToVendor.error) {
114+
setFormSubmitting(false)
115+
setCreateRequestError(sentToVendor.error)
116+
}
106117

107118
setCreatedRequestUUID(data.uuid)
108119
}
109120

110121
useEffect(() => {
111122
if (createdRequestUUID) {
112123
router.push({
113-
pathname: `/requests/${createdRequestUUID}`
114-
})
124+
pathname: `/requests/${createdRequestUUID}`,
125+
query: { createRequestError: JSON.stringify(createRequestError) },
126+
}, `/requests/${createdRequestUUID}`)
115127
}
116128
// eslint-disable-next-line react-hooks/exhaustive-deps
117-
}, [createdRequestUUID])
129+
}, [createdRequestUUID, createRequestError])
118130

119131
// TODO(alishaevn): use react bs placeholder component
120132
if (isLoadingInitialRequest || !wareID || formSubmitting) return <Loading wrapperClass='item-page mt-5' />

utils/api/configurations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const configureRequests = ({ data, path }) => {
7373
title: `${request.identifier}: ${request.name}`,
7474
updatedAt: normalizeDate(request.updated_at),
7575
uuid: request.uuid,
76-
quotedWareID: request.quoted_ware_refs?.[0].id,
76+
quotedWareID: request.quoted_ware_refs?.[0]?.id,
7777
}
7878
})
7979
}
@@ -85,7 +85,7 @@ export const configureErrors = (errors) => {
8585
.filter(error => error && Object.keys(error).length)
8686
.map(error => ({
8787
...error,
88-
message: `${error.message} (${error.response?.data?.message})`,
88+
message: `${error.message} (${error.response?.data?.message || ''})`,
8989
}))
9090
let body = []
9191
let title = ''

utils/api/requests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ export const acceptSOWandCreatePO = (request, sow, accessToken) => {
279279
billing: request.billingAddress,
280280
})
281281

282+
/* eslint-disable camelcase */
282283
const pg_quote_group = {
283284
...sharedRequestData,
284285
name: request.title,
285286
description: request.description,
286-
/* eslint-disable camelcase */
287287
provider_names: [process.env.NEXT_PUBLIC_PROVIDER_NAME],
288288
winning_proposal_id: sow.id,
289289
purchase_justifications: [''],

utils/api/webhooks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const getWebhookConfig = async (accessToken) => {
99
}
1010

1111
export const createWebhookConfig = (accessToken) => {
12+
/* eslint-disable camelcase */
1213
const webhook_config = {
1314
'name': 'Webstore',
1415
'url': `${process.env.NEXT_PUBLIC_WEBHOOK_URL}`,
@@ -28,4 +29,5 @@ export const createWebhookConfig = (accessToken) => {
2829
// https://github.com/assaydepot/scientist_api_v2/pull/237 is available on api prod
2930
const url = () => accessToken ? '/webhook_config.json' : null
3031
updating(url(), webhook_config, accessToken)
32+
/* eslint-enable camelcase */
3133
}

0 commit comments

Comments
 (0)