@@ -19,9 +19,9 @@ import (
1919 "github.com/riverqueue/river/rivershared/util/ptrutil"
2020 "github.com/riverqueue/river/rivershared/util/sliceutil"
2121 "github.com/riverqueue/river/rivertype"
22+ "github.com/riverqueue/riverapiframe/apiendpoint"
23+ "github.com/riverqueue/riverapiframe/apierror"
2224
23- "riverqueue.com/riverui/internal/apiendpoint"
24- "riverqueue.com/riverui/internal/apierror"
2525 "riverqueue.com/riverui/internal/dbsqlc"
2626 "riverqueue.com/riverui/internal/querycacher"
2727 "riverqueue.com/riverui/internal/util/pgxutil"
@@ -104,7 +104,7 @@ func (a *healthCheckGetEndpoint) Execute(ctx context.Context, req *healthCheckGe
104104 // fall through to OK status response below
105105
106106 default :
107- return nil , apierror .NewNotFound ("Health check %q not found. Use either `complete` or `minimal`." , req .Name )
107+ return nil , apierror .NewNotFoundf ("Health check %q not found. Use either `complete` or `minimal`." , req .Name )
108108 }
109109
110110 return statusResponseOK , nil
@@ -142,7 +142,7 @@ func (a *jobCancelEndpoint) Execute(ctx context.Context, req *jobCancelRequest)
142142 job , err := a .client .JobCancelTx (ctx , tx , jobID )
143143 if err != nil {
144144 if errors .Is (err , river .ErrNotFound ) {
145- return nil , apierror . NewNotFoundJob (jobID )
145+ return nil , NewNotFoundJob (jobID )
146146 }
147147 return nil , err
148148 }
@@ -185,10 +185,10 @@ func (a *jobDeleteEndpoint) Execute(ctx context.Context, req *jobDeleteRequest)
185185 _ , err := a .client .JobDeleteTx (ctx , tx , jobID )
186186 if err != nil {
187187 if errors .Is (err , rivertype .ErrJobRunning ) {
188- return nil , apierror .NewBadRequest ("Job %d is running and can't be deleted until it finishes." , jobID )
188+ return nil , apierror .NewBadRequestf ("Job %d is running and can't be deleted until it finishes." , jobID )
189189 }
190190 if errors .Is (err , river .ErrNotFound ) {
191- return nil , apierror . NewNotFoundJob (jobID )
191+ return nil , NewNotFoundJob (jobID )
192192 }
193193 return nil , err
194194 }
@@ -227,7 +227,7 @@ func (req *jobGetRequest) ExtractRaw(r *http.Request) error {
227227
228228 jobID , err := strconv .ParseInt (idString , 10 , 64 )
229229 if err != nil {
230- return apierror .NewBadRequest ("Couldn't convert job ID to int64: %s." , err )
230+ return apierror .NewBadRequestf ("Couldn't convert job ID to int64: %s." , err )
231231 }
232232 req .JobID = jobID
233233
@@ -239,7 +239,7 @@ func (a *jobGetEndpoint) Execute(ctx context.Context, req *jobGetRequest) (*Rive
239239 job , err := a .client .JobGetTx (ctx , tx , req .JobID )
240240 if err != nil {
241241 if errors .Is (err , river .ErrNotFound ) {
242- return nil , apierror . NewNotFoundJob (req .JobID )
242+ return nil , NewNotFoundJob (req .JobID )
243243 }
244244 return nil , fmt .Errorf ("error getting job: %w" , err )
245245 }
@@ -276,7 +276,7 @@ func (req *jobListRequest) ExtractRaw(r *http.Request) error {
276276 if limitStr := r .URL .Query ().Get ("limit" ); limitStr != "" {
277277 limit , err := strconv .Atoi (limitStr )
278278 if err != nil {
279- return apierror .NewBadRequest ("Couldn't convert `limit` to integer: %s." , err )
279+ return apierror .NewBadRequestf ("Couldn't convert `limit` to integer: %s." , err )
280280 }
281281
282282 req .Limit = & limit
@@ -344,7 +344,7 @@ func (a *jobRetryEndpoint) Execute(ctx context.Context, req *jobRetryRequest) (*
344344 _ , err := a .client .JobRetryTx (ctx , tx , jobID )
345345 if err != nil {
346346 if errors .Is (err , river .ErrNotFound ) {
347- return nil , apierror . NewNotFoundJob (jobID )
347+ return nil , NewNotFoundJob (jobID )
348348 }
349349 return nil , err
350350 }
@@ -388,7 +388,7 @@ func (a *queueGetEndpoint) Execute(ctx context.Context, req *queueGetRequest) (*
388388 queue , err := a .client .QueueGetTx (ctx , tx , req .Name )
389389 if err != nil {
390390 if errors .Is (err , river .ErrNotFound ) {
391- return nil , apierror . NewNotFoundQueue (req .Name )
391+ return nil , NewNotFoundQueue (req .Name )
392392 }
393393 return nil , fmt .Errorf ("error getting queue: %w" , err )
394394 }
@@ -430,7 +430,7 @@ func (req *queueListRequest) ExtractRaw(r *http.Request) error {
430430 if limitStr := r .URL .Query ().Get ("limit" ); limitStr != "" {
431431 limit , err := strconv .Atoi (limitStr )
432432 if err != nil {
433- return apierror .NewBadRequest ("Couldn't convert `limit` to integer: %s." , err )
433+ return apierror .NewBadRequestf ("Couldn't convert `limit` to integer: %s." , err )
434434 }
435435
436436 req .Limit = & limit
@@ -490,7 +490,7 @@ func (a *queuePauseEndpoint) Execute(ctx context.Context, req *queuePauseRequest
490490 return pgxutil .WithTxV (ctx , a .dbPool , func (ctx context.Context , tx pgx.Tx ) (* statusResponse , error ) {
491491 if err := a .client .QueuePauseTx (ctx , tx , req .Name , nil ); err != nil {
492492 if errors .Is (err , river .ErrNotFound ) {
493- return nil , apierror . NewNotFoundQueue (req .Name )
493+ return nil , NewNotFoundQueue (req .Name )
494494 }
495495 return nil , fmt .Errorf ("error pausing queue: %w" , err )
496496 }
@@ -532,7 +532,7 @@ func (a *queueResumeEndpoint) Execute(ctx context.Context, req *queueResumeReque
532532 return pgxutil .WithTxV (ctx , a .dbPool , func (ctx context.Context , tx pgx.Tx ) (* statusResponse , error ) {
533533 if err := a .client .QueueResumeTx (ctx , tx , req .Name , nil ); err != nil {
534534 if errors .Is (err , river .ErrNotFound ) {
535- return nil , apierror . NewNotFoundQueue (req .Name )
535+ return nil , NewNotFoundQueue (req .Name )
536536 }
537537 return nil , fmt .Errorf ("error resuming queue: %w" , err )
538538 }
@@ -670,7 +670,7 @@ func (a *workflowGetEndpoint) Execute(ctx context.Context, req *workflowGetReque
670670 }
671671
672672 if len (jobs ) < 1 {
673- return nil , apierror . NewNotFoundWorkflow (req .ID )
673+ return nil , NewNotFoundWorkflow (req .ID )
674674 }
675675
676676 return & workflowGetResponse {
@@ -712,7 +712,7 @@ func (req *workflowListRequest) ExtractRaw(r *http.Request) error {
712712 if limitStr := r .URL .Query ().Get ("limit" ); limitStr != "" {
713713 limit , err := strconv .Atoi (limitStr )
714714 if err != nil {
715- return apierror .NewBadRequest ("Couldn't convert `limit` to integer: %s." , err )
715+ return apierror .NewBadRequestf ("Couldn't convert `limit` to integer: %s." , err )
716716 }
717717
718718 req .Limit = & limit
@@ -758,6 +758,18 @@ func (a *workflowListEndpoint) Execute(ctx context.Context, req *workflowListReq
758758 }
759759}
760760
761+ func NewNotFoundJob (jobID int64 ) * apierror.NotFound {
762+ return apierror .NewNotFoundf ("Job not found: %d." , jobID )
763+ }
764+
765+ func NewNotFoundQueue (name string ) * apierror.NotFound {
766+ return apierror .NewNotFoundf ("Queue not found: %s." , name )
767+ }
768+
769+ func NewNotFoundWorkflow (id string ) * apierror.NotFound {
770+ return apierror .NewNotFoundf ("Workflow not found: %s." , id )
771+ }
772+
761773type RiverJob struct {
762774 ID int64 `json:"id"`
763775 Args json.RawMessage `json:"args"`
0 commit comments