1
1
import { getTrigger , Types } from "./TriggerStore" ;
2
2
import { maybeRunValidator } from "./Validator" ;
3
- import { logTriggerAfterHook , logTriggerErrorBeforeHook } from "./Logger" ;
3
+ import { logTriggerAfterHook } from "./Logger" ;
4
4
import { toJSONwithObjects , resolveError } from "./Utils" ;
5
5
6
6
export function getRequestObject (
@@ -57,37 +57,36 @@ export async function maybeRunTrigger(
57
57
parseObject ,
58
58
originalParseObject ,
59
59
config ,
60
- context ,
61
- responseObject
60
+ context
62
61
) {
63
- if ( ! parseObject ) {
64
- return { } ;
65
- }
62
+ try {
63
+ if ( ! parseObject ) {
64
+ return { } ;
65
+ }
66
66
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
+ }
71
71
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
+ ) ;
80
80
81
- try {
82
81
await maybeRunValidator ( request , `${ triggerType } .${ parseObject . className } ` , auth ) ;
83
82
84
83
if ( request . skipWithMasterKey ) {
85
84
return ;
86
85
}
87
86
88
- const promise = trigger ( request , responseObject ) ;
87
+ const response = await trigger ( request ) ;
89
88
90
- if ( [ Types . afterSave , Types . afterDelete , Types . afterLogin ] . includes ( triggerType ) ) {
89
+ if ( triggerType === Types . afterSave || triggerType === Types . afterDelete ) {
91
90
logTriggerAfterHook (
92
91
triggerType ,
93
92
parseObject . className ,
@@ -97,24 +96,9 @@ export async function maybeRunTrigger(
97
96
) ;
98
97
}
99
98
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 , {
118
102
code : Parse . Error . SCRIPT_FAILED ,
119
103
message : 'Script failed.' ,
120
104
} ) ;
0 commit comments