@@ -5,10 +5,18 @@ import {
55 faTriangleExclamation ,
66 Icon ,
77} from "@rivet-gg/icons" ;
8+ import type { Rivet } from "@rivetkit/engine-api-full" ;
89import { useInfiniteQuery , useQuery } from "@tanstack/react-query" ;
910import { AnimatePresence , motion } from "framer-motion" ;
1011import { useEffect } from "react" ;
11- import { useController , useFieldArray , useForm , useFormContext , useWatch } from "react-hook-form" ;
12+ import {
13+ useController ,
14+ useFieldArray ,
15+ useForm ,
16+ useFormContext ,
17+ useWatch ,
18+ } from "react-hook-form" ;
19+ import { match , P } from "ts-pattern" ;
1220import { useDebounceValue } from "usehooks-ts" ;
1321import z from "zod" ;
1422import {
@@ -33,9 +41,8 @@ import {
3341 SelectValue ,
3442} from "@/components" ;
3543import { useEngineCompatDataProvider } from "@/components/actors" ;
36- import { VisibilitySensor } from "@/components/visibility-sensor" ;
3744import { defineStepper } from "@/components/ui/stepper" ;
38- import { Rivet } from "@rivetkit/engine-api-full " ;
45+ import { VisibilitySensor } from "@/components/visibility-sensor " ;
3946
4047const endpointSchema = z
4148 . string ( )
@@ -405,7 +412,13 @@ const code = ({ plan }: { plan: string }) =>
405412export const Json = ( { plan } : { plan : string } ) => {
406413 return (
407414 < div className = "space-y-2 mt-2" >
408- < CodeFrame language = "json" title = "vercel.json" code = { ( ) => code ( { plan} ) . replaceAll ( " // [!code highlight]" , "" ) } >
415+ < CodeFrame
416+ language = "json"
417+ title = "vercel.json"
418+ code = { ( ) =>
419+ code ( { plan } ) . replaceAll ( " // [!code highlight]" , "" )
420+ }
421+ >
409422 < CodePreview
410423 className = "w-full min-w-0"
411424 language = "json"
@@ -442,7 +455,8 @@ export const Endpoint = ({
442455 < Input
443456 type = "url"
444457 placeholder = {
445- placeholder || "https://my-rivet-app.vercel.app/api/rivet"
458+ placeholder ||
459+ "https://my-rivet-app.vercel.app/api/rivet"
446460 }
447461 { ...field }
448462 />
@@ -462,15 +476,15 @@ export function ConnectionCheck() {
462476
463477 const enabled = ! ! endpoint && endpointSchema . safeParse ( endpoint ) . success ;
464478
465- console . log ( enabled ) ;
466-
467479 const [ debounced ] = useDebounceValue ( endpoint , 300 ) ;
468480
469481 const { isSuccess, data, isError, isRefetchError, isLoadingError, error } =
470482 useQuery ( {
471483 ...dataProvider . runnerHealthCheckQueryOptions ( {
472484 runnerUrl : debounced ,
473- headers : Object . fromEntries ( headers . filter ( ( [ k , v ] ) => k && v ) . map ( ( [ k , v ] ) => [ k , v ] ) ) ,
485+ headers : Object . fromEntries (
486+ headers . filter ( ( [ k , v ] ) => k && v ) . map ( ( [ k , v ] ) => [ k , v ] ) ,
487+ ) ,
474488 } ) ,
475489 enabled,
476490 retry : 0 ,
@@ -517,7 +531,9 @@ export function ConnectionCheck() {
517531 Health check failed, verify the endpoint is
518532 correct.
519533 </ p >
520- { isRivetHealthCheckFailureResponse ( error ) ? < p className = "font-mono-console" > { JSON . stringify ( error . failure . error ) } </ p > : null }
534+ { isRivetHealthCheckFailureResponse ( error ) ? (
535+ < HealthCheckFailure error = { error } />
536+ ) : null }
521537 < p >
522538 Endpoint{ " " }
523539 < a
@@ -547,7 +563,58 @@ export function ConnectionCheck() {
547563 ) ;
548564}
549565
566+ function isRivetHealthCheckFailureResponse (
567+ error : any ,
568+ ) : error is Rivet . RunnerConfigsServerlessHealthCheckResponseFailure [ "failure" ] {
569+ return error && "error" in error ;
570+ }
571+
572+ function HealthCheckFailure ( {
573+ error,
574+ } : {
575+ error : Rivet . RunnerConfigsServerlessHealthCheckResponseFailure [ "failure" ] ;
576+ } ) {
577+ if ( ! ( "error" in error ) ) {
578+ return null ;
579+ }
580+ if ( ! error . error ) {
581+ return null ;
582+ }
550583
551- function isRivetHealthCheckFailureResponse ( error : any ) : error is Rivet . RunnerConfigsServerlessHealthCheckResponseFailure {
552- return error && 'failure' in error ;
553- }
584+ return match ( error . error )
585+ . with ( { nonSuccessStatus : P . any } , ( e ) => {
586+ return (
587+ < p >
588+ Health check failed with status{ " " }
589+ { e . nonSuccessStatus . statusCode }
590+ </ p >
591+ ) ;
592+ } )
593+ . with ( { invalidRequest : P . any } , ( e ) => {
594+ return < p > Health check failed because the request was invalid.</ p > ;
595+ } )
596+ . with ( { invalidResponseJson : P . any } , ( e ) => {
597+ return (
598+ < p >
599+ Health check failed because the response was not valid JSON.
600+ </ p >
601+ ) ;
602+ } )
603+ . with ( { requestFailed : P . any } , ( e ) => {
604+ return (
605+ < p >
606+ Health check failed because the request could not be
607+ completed.
608+ </ p >
609+ ) ;
610+ } )
611+ . with ( { requestTimedOut : P . any } , ( e ) => {
612+ return < p > Health check failed because the request timed out.</ p > ;
613+ } )
614+ . with ( { invalidResponseSchema : P . any } , ( e ) => {
615+ return (
616+ < p > Health check failed because the response was not valid.</ p >
617+ ) ;
618+ } )
619+ . exhaustive ( ) ;
620+ }
0 commit comments