@@ -19,6 +19,7 @@ import Data.Variant (Variant)
1919import Data.Variant as Variant
2020import Prim.Row (class Cons)
2121import Prim.RowList as RL
22+import Prim.TypeError (class Fail, Text, Above)
2223import Type.Proxy (Proxy(..))
2324import Unsafe.Coerce (unsafeCoerce)
2425
@@ -70,6 +71,43 @@ instance toResponseRLBodyHeaders ::
7071else instance toResponseRLBodyOnly ::
7172 ToResponseRL (RL.Cons "body" body RL.Nil) () body
7273
74+-- Invalid record structure: has fields other than "body" and "headers"
75+else instance toResponseRLInvalid ::
76+ ( Fail
77+ ( Above
78+ (Text "Invalid response record structure.")
79+ ( Above
80+ (Text "")
81+ ( Above
82+ (Text "Response records must contain ONLY:")
83+ ( Above
84+ (Text " • body :: YourBodyType (required)")
85+ ( Above
86+ (Text " • headers :: Record (...) (optional)")
87+ ( Above
88+ (Text "")
89+ ( Above
90+ (Text "Valid examples:")
91+ ( Above
92+ (Text " { body: user }")
93+ ( Above
94+ (Text " { body: user, headers: { \"Location\": \"/users/123\" } }")
95+ ( Above
96+ (Text "")
97+ (Text "Do not include 'status', 'statusCode', or other fields.")
98+ )
99+ )
100+ )
101+ )
102+ )
103+ )
104+ )
105+ )
106+ )
107+ )
108+ ) =>
109+ ToResponseRL rl headers body
110+
73111--------------------------------------------------------------------------------
74112-- Response Construction Helpers
75113--------------------------------------------------------------------------------