Skip to content

Commit

Permalink
Task now keeps the rejected value as error
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhudec committed Mar 8, 2024
1 parent cf349b1 commit c816e94
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/apps/interactions/apps/details-form/client/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ export function saveInteraction({ values, companyIds, referralId }) {
.catch((e) => {
// Accounts for non-standard API error on contacts field
const contactsError = e.response?.data?.contacts[0]
return contactsError ? Promise.reject(contactsError) : catchApiError(e)
return contactsError
? Promise.reject(contactsError)
: catchApiError(e).message
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/client/components/AccessDenied/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react'
import DefaultLayout from '../Layout/DefaultLayout'

const AccessDenied = ({ breadcrumbs }) => (
// FIXME: This shouldn't DefaultLayout as it can appear anywhere in a page in which case
// it completely breaks the layout.
<DefaultLayout
heading="You don't have permission to view this page"
pageTitle="Access denied"
Expand Down
11 changes: 10 additions & 1 deletion src/client/components/Task/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ const startOnRenderPropTypes = {
* @typedef Task
* @property {'progress' | 'error'} status - The current status of the task
* @property {Boolean} progress - Whether the task is in progress
* @property {Boolean} error - Whether the task is in error state
* @property {Boolean} isError - Whether the task is in error state
* @property {(name, id, StartOptions) => void} start - Starts a task.
* @property {any} [payload=undefined] - The value of the payload with which the task was started.
* @property {any} [error=undefined] - The value with wich the task rejected
* @property {string} [errorMessage=undefined] - Error message extracted from {error.message}.
* @property {string} [onSuccessDispatch=undefined] - Action that will be dispatched when the task resolves
* @property {() => void} [dismissError=undefined] - When when the task is in `state === 'error'`
* will reset the tasks state.
*/

/**
Expand Down Expand Up @@ -245,6 +251,7 @@ Task.Status = ({
errorMessage,
onSuccessDispatch,
dismissError,
error,
} = getTask(name, id)

const retry = () =>
Expand All @@ -263,12 +270,14 @@ Task.Status = ({
progress &&
renderProgress({ message: progressMessage, noun })}
{isError &&
// FIXME: This is shouldn't be done here and it shouldn't be done this way
(errorMessage ===
'You do not have permission to perform this action.' ? (
<AccessDenied />
) : (
renderError({
noun,
error,
errorMessage,
retry: !noRetry && retry,
dismiss: !noDismiss && dismissError,
Expand Down
3 changes: 2 additions & 1 deletion src/client/components/Task/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function* startTask(task, action) {
type: TASK__ERROR,
id,
name,
errorMessage: error,
error,
errorMessage: error.message,
})
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/client/components/Task/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ export const delay = curry((duration, task, payload) =>
)

export const catchApiError = ({ response, message }) =>
Promise.reject(
response?.data?.detail ||
Promise.reject({
message:
response?.data?.detail ||
response?.text ||
response?.data?.non_field_errors ||
(response?.data && {
errors: response.data,
httpStatusCode: response.status,
}) ||
response?.statusText ||
message
)
response.data ||
message,
httpStatusCode: response.status,
})

/**
* A custom Axios instance for easy access to the `/api-proxy` endpoint.
Expand Down
2 changes: 1 addition & 1 deletion src/client/modules/ExportWins/Review/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ThankYou from './ThankYou'
const FORM_ID = 'export-wins-customer-feedback'

const NotFound = (props) =>
props.errorMessage?.httpStatusCode === 404 ? (
props.error?.httpStatusCode === 404 ? (
<>
<H4 as="h2">The link you used has expired</H4>
<p>
Expand Down

0 comments on commit c816e94

Please sign in to comment.