Skip to content

Commit

Permalink
add catches to request calls
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Jan 7, 2024
1 parent 0ab7543 commit a514580
Show file tree
Hide file tree
Showing 30 changed files with 767 additions and 559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import _omit from 'lodash/omit'
import AssociatedChallengeList from './AssociatedChallengeList';

const getChallengeById = async (id) => {
const result = await new Endpoint(api.challenge.single, { variables: { id }, schema: challengeSchema() }).execute()
try {
const result = await new Endpoint(api.challenge.single, { variables: { id }, schema: challengeSchema() }).execute()

return result
return result
} catch (error) {
console.error('Error fetching challenge by ID:', error)
}
}

const ChallengeIdResult = (props) => {
Expand Down
18 changes: 11 additions & 7 deletions src/components/HOCs/WithChallenge/WithChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,18 @@ export const getChallenge = (challengeId, props, component) => {
}

const getChallengeFromTask = async (taskId, props) => {
const results = await new Endpoint(api.task.single, {
schema: taskSchema(),
variables: {id: taskId}
}).execute();
try {
const results = await new Endpoint(api.task.single, {
schema: taskSchema(),
variables: {id: taskId}
}).execute();

const challengeId = results?.entities?.tasks?.[taskId]?.parent;
if (challengeId) {
props.history.push(`/challenge/${challengeId}/task/${taskId}/review`)
const challengeId = results?.entities?.tasks?.[taskId]?.parent;
if (challengeId) {
props.history.push(`/challenge/${challengeId}/task/${taskId}/review`)
}
} catch (error) {
console.error('Error fetching challenge from task:', error)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/SignInButton/SignInButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SignInButton extends Component {
}

render() {
if (this.props.checkingLoginStatus || this.state.clicked) {
if (this.state.clicked) {
return (
<BusySpinner
className={classNames("mr-mx-8", {"mr-mx-20": this.props.longForm})}
Expand Down
10 changes: 7 additions & 3 deletions src/hooks/UseErrorTagOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { defaultRoutes as api } from "../../services/Server/Server";
import Endpoint from "../../services/Server/Endpoint";

const useErrorTagOptions = () => {
const query = useQuery('errorTags', () =>
new Endpoint(api.keywords.find, { params: { tagType: "error", limit: 1000 } }).execute()
)
const query = useQuery('errorTags', async () => {
try {
return await new Endpoint(api.keywords.find, { params: { tagType: "error", limit: 1000 } }).execute();
} catch (error) {
console.error('Error fetching error tags:', error)
}
})

return query;
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/AdminContext/AdminContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const clearManagedChallenge = function() {

// async action creators
export const manageProject = function(projectId) {
return function(dispatch) {
return async function(dispatch) {
dispatch(beginManagingProject(projectId, RequestStatus.inProgress))

return fetchProjectChallenges(projectId)(dispatch)
Expand All @@ -50,7 +50,7 @@ export const manageProject = function(projectId) {
}

export const manageChallenge = function(challengeId) {
return function(dispatch) {
return async function(dispatch) {
dispatch(beginManagingChallenge(challengeId, RequestStatus.inProgress))

return fetchChallengeTasks(challengeId)(dispatch)
Expand Down
Loading

0 comments on commit a514580

Please sign in to comment.