MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / mapErr

Function mapErr

api/src/utils/index.ts:80–86  ·  view source on GitHub ↗
(promise: Promise<T>)

Source from the content-addressed store, hash-verified

78 * @returns a promise with either the data or the caught error
79 */
80export async function mapErr<T>(promise: Promise<T>): Promise<Result<T>> {
81 try {
82 return { hasError: false, data: await promise };
83 } catch (error) {
84 return { hasError: true, error };
85 }
86}
87
88/**
89 * Wrapper around a synchronise function to catch throws and return them as part of the value.

Callers 9

constructEnvExamAttemptFunction · 0.85
postExamAttemptHandlerFunction · 0.85
getExamsFunction · 0.85
getExamAttemptsHandlerFunction · 0.85
getExamAttemptHandlerFunction · 0.85
getExamChallengeFunction · 0.85
userRoutesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected