Files
talk/src/core/server/graph/errors.ts
T
84bbc3d0c3 [CORL-688] Refactor: Consolidate the tenant and common context together (#2780)
* feat: initial impl

* Create preliminary comment moderation slices

CORL-688

* Move slices logic into stacks

CORL-688

* Create user comment counts

CORL-688

* Create naive mutation that initializes user comment counts

CORL-688

* Use bulk updates in user counts migration

CORL-688

* fix: review

* fix: fixed issue with aggregation

* Migrate creating comment into stacks

CORL-688

* Migrate editing a comment to the stacks

CORL-688

* Break publishing comment status out of updateAllCounts

CORL-688

* review: removed variable scoping in favor of export

* revert: feb8e8196cd448f5cd24f1ca2eb0b91fe9bd43c7

* review: simplification of stacks implementation

This simplifies the stacks implementation to better reuse code related
to count management and event publishing. This can be used to great
effect with the upcomming events PR #2738.

* Consolidate the tenant and common context together

CORL-688

* review: removed variable scoping in favor of export

* revert: feb8e8196cd448f5cd24f1ca2eb0b91fe9bd43c7

* review: simplification of stacks implementation

This simplifies the stacks implementation to better reuse code related
to count management and event publishing. This can be used to great
effect with the upcomming events PR #2738.

* fix: check if authorID is null before update user counts

CORL-688

* Consolidate common/tenant context supporting files

CORL-688

* feat: renamed TenantContext -> GraphContext

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
2020-01-08 17:07:25 +00:00

37 lines
1.0 KiB
TypeScript

import { ERROR_CODES } from "coral-common/errors";
import { CoralError } from "coral-server/errors";
/**
* mapFieldsetToErrorCodes will wait for any errors to occur with the request,
* and then associate the appropriate field that caused the error to the error
* itself so it can link context in the UI.
*
* @param promise the promise to await on for any errors to occur
* @param errorMap the map of error codes to associate with a given fieldSet
*/
export async function mapFieldsetToErrorCodes<T>(
promise: Promise<T>,
errorMap: Record<string, ERROR_CODES[]>
): Promise<T> {
try {
return await promise;
} catch (err) {
// If the error is a CoralError...
if (err instanceof CoralError) {
// Then loop over all the fieldSpecs...
for (const param in errorMap) {
if (!errorMap.hasOwnProperty(param)) {
continue;
}
if (errorMap[param].some(code => err.code === code)) {
err.param = param;
break;
}
}
}
throw err;
}
}