Skip to content

Commit

Permalink
Merge pull request #297 from scientist-softserv/295-better-error-hand…
Browse files Browse the repository at this point in the history
…ling

295 better error handling
  • Loading branch information
alishaevn authored Apr 5, 2023
2 parents 499a0e4 + 6bdc6e4 commit b9b23dc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
29 changes: 28 additions & 1 deletion pages/requests/[uuid].js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Request = ({ session }) => {
* as a dynamically routed file, the router query will always consist of a "key: value" pair that's determined by the name of
* the file (key) and path string (value). additional query properties may also exist if they were explicitly passed.
*/
const { uuid } = router.query
const { createRequestError, uuid } = router.query
const accessToken = session?.accessToken
const { request, isLoadingRequest, isRequestError } = useOneRequest(uuid, accessToken)
const { allSOWs, isLoadingSOWs, isSOWError } = useAllSOWs(uuid, request?.identifier, accessToken)
Expand Down Expand Up @@ -78,6 +78,33 @@ const Request = ({ session }) => {
)
}

// this error is a result of creating the request
if (createRequestError) {
// TODO(alishaevn): how to handle a "sent to vendor" error?
const attachmentError = JSON.parse(createRequestError).config.url.includes('notes')

return (
<Notice
alert={attachmentError &&
{
body: ['Your attachment failed. Please visit your request and try again from the "View Files" tab.'],
title: 'Attachment Error',
variant: 'info',
}
}
dismissible={false}
withBackButton={true}
buttonProps={attachmentError &&
{
onClick: () => router.push({ pathname: `/requests/${uuid}` }),
text: 'Click to view your request.',
}
}
/>
)
}

// this error is a result of getting the request or its related data
if (isError) {
return (
<Notice
Expand Down
22 changes: 17 additions & 5 deletions pages/requests/new/[ware].js
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,34 @@ const NewRequest = ({ session }) => {
wareID,
accessToken,
})
if (error) return setCreateRequestError(error)
// if we have data AND an error, the request was created, but the attachments failed
// in that case, we still need to send the request to the vendor
if (error && !data) {
setFormSubmitting(false)
setCreateRequestError(error)
return
} else if (error) {
setCreateRequestError(error)
}

const sentToVendor = await sendRequestToVendor(data.id, accessToken)
if (sentToVendor.error) return setCreateRequestError(sentToVendor.error)
if (sentToVendor.error) {
setFormSubmitting(false)
setCreateRequestError(sentToVendor.error)
}

setCreatedRequestUUID(data.uuid)
}

useEffect(() => {
if (createdRequestUUID) {
router.push({
pathname: `/requests/${createdRequestUUID}`
})
pathname: `/requests/${createdRequestUUID}`,
query: { createRequestError: JSON.stringify(createRequestError) },
}, `/requests/${createdRequestUUID}`)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [createdRequestUUID])
}, [createdRequestUUID, createRequestError])

// TODO(alishaevn): use react bs placeholder component
if (isLoadingInitialRequest || !wareID || formSubmitting) return <Loading wrapperClass='item-page mt-5' />
Expand Down
4 changes: 2 additions & 2 deletions utils/api/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const configureRequests = ({ data, path }) => {
title: `${request.identifier}: ${request.name}`,
updatedAt: normalizeDate(request.updated_at),
uuid: request.uuid,
quotedWareID: request.quoted_ware_refs?.[0].id,
quotedWareID: request.quoted_ware_refs?.[0]?.id,
}
})
}
Expand All @@ -85,7 +85,7 @@ export const configureErrors = (errors) => {
.filter(error => error && Object.keys(error).length)
.map(error => ({
...error,
message: `${error.message} (${error.response?.data?.message})`,
message: `${error.message} (${error.response?.data?.message || ''})`,
}))
let body = []
let title = ''
Expand Down
2 changes: 1 addition & 1 deletion utils/api/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ export const acceptSOWandCreatePO = (request, sow, accessToken) => {
billing: request.billingAddress,
})

/* eslint-disable camelcase */
const pg_quote_group = {
...sharedRequestData,
name: request.title,
description: request.description,
/* eslint-disable camelcase */
provider_names: [process.env.NEXT_PUBLIC_PROVIDER_NAME],
winning_proposal_id: sow.id,
purchase_justifications: [''],
Expand Down
2 changes: 2 additions & 0 deletions utils/api/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const getWebhookConfig = async (accessToken) => {
}

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

1 comment on commit b9b23dc

@vercel
Copy link

@vercel vercel bot commented on b9b23dc Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.