Skip to content

Commit f8d1b1d

Browse files
authored
Merge pull request #293 from scientist-softserv/292-reduce-sentry-errors
292 reduce sentry errors
2 parents 4ac21dc + b545c6c commit f8d1b1d

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

utils/api/requests.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { fetcher, posting, updating } from './base'
1212

1313
/** GET METHODS */
1414
export const useAllRequests = (accessToken) => {
15-
const { data, error } = useSWR([`/quote_groups/mine.json`, accessToken])
15+
const { data, error } = useSWR(accessToken ? [`/quote_groups/mine.json`, accessToken] : null)
1616
const requests = data && configureRequests({ data: data.quote_group_refs, path: '/requests' })
1717

1818
return {
@@ -23,7 +23,7 @@ export const useAllRequests = (accessToken) => {
2323
}
2424

2525
export const useOneRequest = (uuid, accessToken) => {
26-
const { data, error } = useSWR(uuid ? [`/quote_groups/${uuid}.json`, accessToken] : null)
26+
const { data, error } = useSWR(accessToken ? [`/quote_groups/${uuid}.json`, accessToken] : null)
2727
let request = data && configureRequests({ data, path: '/requests' })[0]
2828
if (request) {
2929
request = {
@@ -43,7 +43,7 @@ export const useOneRequest = (uuid, accessToken) => {
4343
}
4444

4545
export const useAllSOWs = (id, requestIdentifier, accessToken) => {
46-
const { data, error } = useSWR(id ? [`/quote_groups/${id}/proposals.json`, accessToken] : null)
46+
const { data, error } = useSWR(accessToken ? [`/quote_groups/${id}/proposals.json`, accessToken] : null)
4747
let allSOWs
4848
if (data) {
4949
allSOWs = configureSOWs(data, requestIdentifier)
@@ -62,7 +62,8 @@ export const getAllPOs = async (quotedWareId, uuid, requestIdentifier, accessTok
6262
// TODO(summer-cook): eventually we can use the useSWRList hook here instead of mapping & calling the fetcher.
6363
// This hook is actively being contributed to the swr repo, but the semantics of the work are still being debated.
6464
// See https://github.com/vercel/swr/discussions/1988 for the RFC and https://github.com/vercel/swr/pull/2047 for the PR.
65-
const data = await fetcher(`quote_groups/${uuid}/quoted_wares/${quotedWareId}/purchase_orders.json`, accessToken)
65+
const url = () => accessToken ? `quote_groups/${uuid}/quoted_wares/${quotedWareId}/purchase_orders.json` : null
66+
const data = await fetcher(url(), accessToken)
6667
const configuredPOs = data?.map(async (po) => {
6768
const purchaseOrder = await fetcher(`quote_groups/${uuid}/quoted_wares/${quotedWareId}/purchase_orders/${po.id}.json`, accessToken)
6869
return configurePO(purchaseOrder, requestIdentifier)
@@ -84,12 +85,14 @@ export const getAllPOs = async (quotedWareId, uuid, requestIdentifier, accessTok
8485
}
8586

8687
export const useMessages = (requestUuid, accessToken) => {
87-
const { data, error, mutate } = useSWR(requestUuid ? [`/quote_groups/${requestUuid}/messages.json`, accessToken] : null)
88+
const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${requestUuid}/messages.json`, accessToken] : null)
8889
let messages
8990
if (data) {
9091
messages = configureMessages(data.messages)
9192
}
9293

94+
// TODO(alishaevn): check that we don't need to change anything here when
95+
// https://github.com/assaydepot/scientist_api_v2/issues/251 is resolved
9396
return {
9497
messages,
9598
mutateMessages: mutate,
@@ -100,7 +103,7 @@ export const useMessages = (requestUuid, accessToken) => {
100103
}
101104

102105
export const useFiles = (id, accessToken) => {
103-
const { data, error, mutate } = useSWR(id ? [`/quote_groups/${id}/notes.json`, accessToken] : null)
106+
const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${id}/notes.json`, accessToken] : null)
104107
let files
105108
if (data) {
106109
files = configureFiles(data.notes)
@@ -117,7 +120,7 @@ export const useFiles = (id, accessToken) => {
117120

118121

119122
export const useInitializeRequest = (id, accessToken) => {
120-
const { data, error } = useSWR(id ? [`/wares/${id}/quote_groups/new.json`, accessToken] : null)
123+
const { data, error } = useSWR(accessToken ? [`/wares/${id}/quote_groups/new.json`, accessToken] : null)
121124
let dynamicForm = { name: data?.name }
122125
let dynamicFormInfo = data?.dynamic_forms[0]
123126

@@ -141,7 +144,7 @@ export const useInitializeRequest = (id, accessToken) => {
141144
}
142145

143146
export const useDefaultWare = (accessToken) => {
144-
const { data, error } = useSWR([`/wares.json`, accessToken])
147+
const { data, error } = useSWR(accessToken ? [`/wares.json`, accessToken] : null)
145148
const defaultWare = data?.ware_refs?.find(item => item.slug === 'make-a-request')
146149

147150
return {
@@ -169,7 +172,8 @@ export const createMessageOrFile = ({ id, quotedWareID, message, files, accessTo
169172
}
170173
/* eslint-enable camelcase */
171174

172-
return posting(`/quote_groups/${id}/notes.json`, note, accessToken)
175+
const url = () => accessToken ? `/quote_groups/${id}/notes.json` : null
176+
return posting(url(), note, accessToken)
173177
}
174178

175179
const requestData = ({request, shipping, billing}) => {
@@ -234,7 +238,8 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
234238
timeline: requestTimeline,
235239
}
236240

237-
let { data, error } = await posting(`/wares/${wareID}/quote_groups.json`, { pg_quote_group }, accessToken)
241+
const url = () => accessToken ? `/wares/${wareID}/quote_groups.json` : null
242+
let { data, error } = await posting(url(), { pg_quote_group }, accessToken)
238243

239244
if (data && dynamicFormData.attachments) {
240245
/**
@@ -245,6 +250,7 @@ export const createRequest = async ({ dynamicFormData, wareID, accessToken }) =>
245250
let quotedWareID = data.quoted_ware_refs?.[0]?.id
246251
if (!quotedWareID) {
247252
// we have to explicity use fetcher because "useOneRequest" is a hook
253+
const url = () => accessToken ? `quote_groups/${uuid}/quoted_wares/${quotedWareId}/purchase_orders.json` : null
248254
const res = await fetcher(`/quote_groups/${data.id}.json`, accessToken)
249255
quotedWareID = res.quoted_ware_refs?.[0]?.id
250256
}
@@ -285,13 +291,15 @@ export const acceptSOWandCreatePO = (request, sow, accessToken) => {
285291
po_number: `PO${sow.identifier}`,
286292
}
287293

288-
return posting(`/quote_groups/${request.id}/accept_sow.json`, { pg_quote_group }, accessToken)
294+
const url = () => accessToken ? `/quote_groups/${request.id}/accept_sow.json` : null
295+
return posting(url(), { pg_quote_group }, accessToken)
289296
/* eslint-enable camelcase */
290297
}
291298

292299
/** PUT METHODS */
293300
export const sendRequestToVendor = async (requestID, accessToken) => {
294-
const { data, error } = await updating(`/quote_groups/${requestID}/send_to_vendors.json`, {}, accessToken)
301+
const url = () => accessToken ? `/quote_groups/${requestID}/send_to_vendors.json` : null
302+
const { data, error } = await updating(url(), {}, accessToken)
295303

296304
return { data, error }
297305
}

utils/api/webhooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { WEBHOOK_EVENTS } from '../constants'
44
export const getWebhookConfig = async (accessToken) => {
55
// TODO(alishaevn): update the url to "webhook_config/user.json" when
66
// https://github.com/assaydepot/scientist_api_v2/pull/237 is available on api prod
7-
return fetcher('/webhook_config.json', accessToken)
7+
const url = () => accessToken ? '/webhook_config.json' : null
8+
return fetcher(url(), accessToken)
89
}
910

1011
export const createWebhookConfig = (accessToken) => {
@@ -25,5 +26,6 @@ export const createWebhookConfig = (accessToken) => {
2526

2627
// TODO(alishaevn): update the url to "webhook_config/user.json" when
2728
// https://github.com/assaydepot/scientist_api_v2/pull/237 is available on api prod
28-
updating('/webhook_config.json', webhook_config, accessToken)
29+
const url = () => accessToken ? '/webhook_config.json' : null
30+
updating(url(), webhook_config, accessToken)
2931
}

0 commit comments

Comments
 (0)