Skip to content

Commit 30866c4

Browse files
committed
fix tests
1 parent d9e0bf2 commit 30866c4

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

src/Triggers/Trigger.js

+23-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getTrigger, Types } from "./TriggerStore";
22
import { maybeRunValidator } from "./Validator";
3-
import { logTriggerAfterHook, logTriggerErrorBeforeHook } from "./Logger";
3+
import { logTriggerAfterHook } from "./Logger";
44
import { toJSONwithObjects, resolveError } from "./Utils";
55

66
export function getRequestObject(
@@ -57,37 +57,36 @@ export async function maybeRunTrigger(
5757
parseObject,
5858
originalParseObject,
5959
config,
60-
context,
61-
responseObject
60+
context
6261
) {
63-
if (!parseObject) {
64-
return {};
65-
}
62+
try {
63+
if (!parseObject) {
64+
return {};
65+
}
6666

67-
const trigger = getTrigger(parseObject.className, triggerType, config.applicationId);
68-
if (!trigger) {
69-
return;
70-
}
67+
const trigger = getTrigger(parseObject.className, triggerType, config.applicationId);
68+
if (!trigger) {
69+
return;
70+
}
7171

72-
const request = getRequestObject(
73-
triggerType,
74-
auth,
75-
parseObject,
76-
originalParseObject,
77-
config,
78-
context
79-
);
72+
const request = getRequestObject(
73+
triggerType,
74+
auth,
75+
parseObject,
76+
originalParseObject,
77+
config,
78+
context
79+
);
8080

81-
try {
8281
await maybeRunValidator(request, `${triggerType}.${parseObject.className}`, auth);
8382

8483
if (request.skipWithMasterKey) {
8584
return;
8685
}
8786

88-
const promise = trigger(request, responseObject);
87+
const response = await trigger(request);
8988

90-
if ([Types.afterSave, Types.afterDelete, Types.afterLogin].includes(triggerType)) {
89+
if (triggerType === Types.afterSave || triggerType === Types.afterDelete) {
9190
logTriggerAfterHook(
9291
triggerType,
9392
parseObject.className,
@@ -97,24 +96,9 @@ export async function maybeRunTrigger(
9796
);
9897
}
9998

100-
const response = await Promise.resolve(promise);
101-
const responseData = processTriggerResponse(request, response);
102-
if (triggerType === Types.beforeSave) {
103-
return responseData?.object ?? null;
104-
}
105-
106-
return responseData;
107-
108-
} catch (err) {
109-
logTriggerErrorBeforeHook(
110-
triggerType,
111-
parseObject.className,
112-
parseObject.toJSON(),
113-
auth,
114-
err,
115-
config.logLevels.triggerBeforeError
116-
);
117-
throw resolveError(err, {
99+
return processTriggerResponse(request, response);
100+
} catch (e) {
101+
throw resolveError(e, {
118102
code: Parse.Error.SCRIPT_FAILED,
119103
message: 'Script failed.',
120104
});

src/Triggers/TriggerStore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ export function getFunctionNames(applicationId) {
205205
};
206206
extractFunctionNames(null, store);
207207
return functionNames;
208-
}
208+
}

0 commit comments

Comments
 (0)