@@ -600,6 +600,34 @@ export async function handleConverse(
600600 return ;
601601
602602 if ( ! fixture ) {
603+ const effectiveStrict = resolveStrictMode ( defaults . strict , req . headers ) ;
604+ if ( effectiveStrict ) {
605+ const strictStatus = 503 ;
606+ const strictMessage = "Strict mode: no fixture matched" ;
607+ logger . error ( `STRICT: No fixture matched for ${ req . method ?? "POST" } ${ urlPath } ` ) ;
608+ journal . add ( {
609+ method : req . method ?? "POST" ,
610+ path : urlPath ,
611+ headers : flattenHeaders ( req . headers ) ,
612+ body : completionReq ,
613+ response : {
614+ status : strictStatus ,
615+ fixture : null ,
616+ ...strictOverrideField ( defaults . strict , req . headers ) ,
617+ } ,
618+ } ) ;
619+ writeErrorResponse (
620+ res ,
621+ strictStatus ,
622+ JSON . stringify ( {
623+ error : {
624+ message : strictMessage ,
625+ type : "invalid_request_error" ,
626+ } ,
627+ } ) ,
628+ ) ;
629+ return ;
630+ }
603631 if ( defaults . record ) {
604632 const outcome = await proxyAndRecord (
605633 req ,
@@ -623,31 +651,22 @@ export async function handleConverse(
623651 return ;
624652 }
625653 }
626- const effectiveStrict = resolveStrictMode ( defaults . strict , req . headers ) ;
627- const strictStatus = effectiveStrict ? 503 : 404 ;
628- const strictMessage = effectiveStrict
629- ? "Strict mode: no fixture matched"
630- : "No fixture matched" ;
631- if ( effectiveStrict ) {
632- logger . error ( `STRICT: No fixture matched for ${ req . method ?? "POST" } ${ urlPath } ` ) ;
633- }
634654 journal . add ( {
635655 method : req . method ?? "POST" ,
636656 path : urlPath ,
637657 headers : flattenHeaders ( req . headers ) ,
638658 body : completionReq ,
639659 response : {
640- status : strictStatus ,
660+ status : 404 ,
641661 fixture : null ,
642- ...strictOverrideField ( defaults . strict , req . headers ) ,
643662 } ,
644663 } ) ;
645664 writeErrorResponse (
646665 res ,
647- strictStatus ,
666+ 404 ,
648667 JSON . stringify ( {
649668 error : {
650- message : strictMessage ,
669+ message : "No fixture matched" ,
651670 type : "invalid_request_error" ,
652671 } ,
653672 } ) ,
@@ -871,6 +890,34 @@ export async function handleConverseStream(
871890 return ;
872891
873892 if ( ! fixture ) {
893+ const effectiveStrict = resolveStrictMode ( defaults . strict , req . headers ) ;
894+ if ( effectiveStrict ) {
895+ const strictStatus = 503 ;
896+ const strictMessage = "Strict mode: no fixture matched" ;
897+ logger . error ( `STRICT: No fixture matched for ${ req . method ?? "POST" } ${ urlPath } ` ) ;
898+ journal . add ( {
899+ method : req . method ?? "POST" ,
900+ path : urlPath ,
901+ headers : flattenHeaders ( req . headers ) ,
902+ body : completionReq ,
903+ response : {
904+ status : strictStatus ,
905+ fixture : null ,
906+ ...strictOverrideField ( defaults . strict , req . headers ) ,
907+ } ,
908+ } ) ;
909+ writeErrorResponse (
910+ res ,
911+ strictStatus ,
912+ JSON . stringify ( {
913+ error : {
914+ message : strictMessage ,
915+ type : "invalid_request_error" ,
916+ } ,
917+ } ) ,
918+ ) ;
919+ return ;
920+ }
874921 if ( defaults . record ) {
875922 const outcome = await proxyAndRecord (
876923 req ,
@@ -894,31 +941,22 @@ export async function handleConverseStream(
894941 return ;
895942 }
896943 }
897- const effectiveStrict = resolveStrictMode ( defaults . strict , req . headers ) ;
898- const strictStatus = effectiveStrict ? 503 : 404 ;
899- const strictMessage = effectiveStrict
900- ? "Strict mode: no fixture matched"
901- : "No fixture matched" ;
902- if ( effectiveStrict ) {
903- logger . error ( `STRICT: No fixture matched for ${ req . method ?? "POST" } ${ urlPath } ` ) ;
904- }
905944 journal . add ( {
906945 method : req . method ?? "POST" ,
907946 path : urlPath ,
908947 headers : flattenHeaders ( req . headers ) ,
909948 body : completionReq ,
910949 response : {
911- status : strictStatus ,
950+ status : 404 ,
912951 fixture : null ,
913- ...strictOverrideField ( defaults . strict , req . headers ) ,
914952 } ,
915953 } ) ;
916954 writeErrorResponse (
917955 res ,
918- strictStatus ,
956+ 404 ,
919957 JSON . stringify ( {
920958 error : {
921- message : strictMessage ,
959+ message : "No fixture matched" ,
922960 type : "invalid_request_error" ,
923961 } ,
924962 } ) ,
0 commit comments