@@ -230,6 +230,19 @@ export function createLoaderApiRoute<
230230 if ( error instanceof Response ) {
231231 return await wrapResponse ( request , error , corsStrategy !== "none" ) ;
232232 }
233+
234+ logger . error ( "Error in loader" , {
235+ error :
236+ error instanceof Error
237+ ? {
238+ name : error . name ,
239+ message : error . message ,
240+ stack : error . stack ,
241+ }
242+ : String ( error ) ,
243+ url : request . url ,
244+ } ) ;
245+
233246 return await wrapResponse (
234247 request ,
235248 json ( { error : "Internal Server Error" } , { status : 500 } ) ,
@@ -770,6 +783,19 @@ export function createLoaderWorkerApiRoute<
770783 if ( error instanceof Response ) {
771784 return error ;
772785 }
786+
787+ logger . error ( "Error in loader" , {
788+ error :
789+ error instanceof Error
790+ ? {
791+ name : error . name ,
792+ message : error . message ,
793+ stack : error . stack ,
794+ }
795+ : String ( error ) ,
796+ url : request . url ,
797+ } ) ;
798+
773799 return json ( { error : "Internal Server Error" } , { status : 500 } ) ;
774800 }
775801 } ;
@@ -785,6 +811,7 @@ type WorkerActionRouteBuilderOptions<
785811 searchParams ?: TSearchParamsSchema ;
786812 headers ?: THeadersSchema ;
787813 body ?: TBodySchema ;
814+ method ?: "POST" | "PUT" | "DELETE" | "PATCH" ;
788815} ;
789816
790817type WorkerActionHandlerFunction <
@@ -823,6 +850,15 @@ export function createActionWorkerApiRoute<
823850 >
824851) {
825852 return async function action ( { request, params } : ActionFunctionArgs ) {
853+ if ( options . method ) {
854+ if ( request . method . toUpperCase ( ) !== options . method ) {
855+ return json (
856+ { error : "Method not allowed" } ,
857+ { status : 405 , headers : { Allow : options . method } }
858+ ) ;
859+ }
860+ }
861+
826862 const {
827863 params : paramsSchema ,
828864 searchParams : searchParamsSchema ,
@@ -903,6 +939,19 @@ export function createActionWorkerApiRoute<
903939 if ( error instanceof Response ) {
904940 return error ;
905941 }
942+
943+ logger . error ( "Error in action" , {
944+ error :
945+ error instanceof Error
946+ ? {
947+ name : error . name ,
948+ message : error . message ,
949+ stack : error . stack ,
950+ }
951+ : String ( error ) ,
952+ url : request . url ,
953+ } ) ;
954+
906955 return json ( { error : "Internal Server Error" } , { status : 500 } ) ;
907956 }
908957 } ;
0 commit comments