Skip to content

Commit 9c93b21

Browse files
committed
catch unhandled exceptions
1 parent 342a01f commit 9c93b21

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/shared/actions/contentful.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getService } from 'services/contentful';
33
import { config, redux } from 'topcoder-react-utils';
44
import { removeTrailingSlash } from 'utils/url';
55
import { menuItemBuilder, target as urlTarget } from 'utils/contentful';
6-
import { services } from 'topcoder-react-lib';
6+
import { services, logger } from 'topcoder-react-lib';
77

88
const ERRMSG_UNKNOWN_TARGET = 'Unknown action target';
99

@@ -91,15 +91,19 @@ async function getContentDone(operationId, contentId, target, preview, spaceName
9191
environment,
9292
});
9393
let content;
94-
switch (target) {
95-
case TARGETS.ASSETS:
96-
content = await service.getAsset(contentId);
97-
break;
98-
case TARGETS.ENTRIES:
99-
content = await service.getEntry(contentId);
100-
break;
101-
default:
102-
throw new Error(ERRMSG_UNKNOWN_TARGET);
94+
try {
95+
switch (target) {
96+
case TARGETS.ASSETS:
97+
content = await service.getAsset(contentId);
98+
break;
99+
case TARGETS.ENTRIES:
100+
content = await service.getEntry(contentId);
101+
break;
102+
default:
103+
throw new Error(ERRMSG_UNKNOWN_TARGET);
104+
}
105+
} catch (e) {
106+
logger.error('getContentDone error', e);
103107
}
104108

105109
return {
@@ -141,15 +145,19 @@ async function queryContentDone(operationId, queryId, target,
141145
environment,
142146
});
143147
let data;
144-
switch (target) {
145-
case TARGETS.ASSETS:
146-
data = await service.queryAssets(query);
147-
break;
148-
case TARGETS.ENTRIES:
149-
data = await service.queryEntries(query);
150-
break;
151-
default:
152-
throw new Error(ERRMSG_UNKNOWN_TARGET);
148+
try {
149+
switch (target) {
150+
case TARGETS.ASSETS:
151+
data = await service.queryAssets(query);
152+
break;
153+
case TARGETS.ENTRIES:
154+
data = await service.queryEntries(query);
155+
break;
156+
default:
157+
throw new Error(ERRMSG_UNKNOWN_TARGET);
158+
}
159+
} catch (e) {
160+
logger.error('queryContentDone error', e);
153161
}
154162

155163
return {

0 commit comments

Comments
 (0)