@@ -198,8 +198,8 @@ func (h SchedulerApiHandler) getScheduledTask(w http.ResponseWriter, r *http.Req
198198 brokerapi .AddInternalError (ctx , w , err )
199199 return sched_db.ScheduledTask {}, ctx , true
200200 }
201- if task . ActionData . BatchActionData = = nil {
202- brokerapi .AddInternalError (ctx , w , errors . New ( "missing batchActionData" ) )
201+ if err := validateBatchActionTask ( task ); err ! = nil {
202+ brokerapi .AddInternalError (ctx , w , err )
203203 return sched_db.ScheduledTask {}, ctx , true
204204 }
205205 return task , ctx , false
@@ -220,6 +220,9 @@ func (h SchedulerApiHandler) DeleteBatchActionsId(w http.ResponseWriter, r *http
220220 if inErr != nil {
221221 return inErr
222222 }
223+ if inErr = validateBatchActionTask (task ); inErr != nil {
224+ return inErr
225+ }
223226 active , inErr := schedRepo .HasActiveBatchActionEvents (ctx , task .ID )
224227 if inErr != nil {
225228 return inErr
@@ -345,8 +348,8 @@ func (h SchedulerApiHandler) mutateScheduledTask(
345348 if inErr != nil {
346349 return inErr
347350 }
348- if task . ActionData . BatchActionData = = nil {
349- return errors . New ( "missing batchActionData" )
351+ if inErr = validateBatchActionTask ( task ); inErr ! = nil {
352+ return inErr
350353 }
351354 mutate (& task )
352355 task , inErr = repo .SaveScheduledTask (ctx , sched_db .SaveScheduledTaskParams (task ))
@@ -355,6 +358,13 @@ func (h SchedulerApiHandler) mutateScheduledTask(
355358 return task , err
356359}
357360
361+ func validateBatchActionTask (task sched_db.ScheduledTask ) error {
362+ if task .ActionData .BatchActionData == nil {
363+ return errors .New ("missing batchActionData" )
364+ }
365+ return nil
366+ }
367+
358368func (h SchedulerApiHandler ) writeScheduledTaskMutationError (ctx common.ExtendedContext , w http.ResponseWriter , err error ) {
359369 if errors .Is (err , pgx .ErrNoRows ) {
360370 brokerapi .AddNotFoundError (w )
0 commit comments