Plug on_finish-sort-of-thing?

Is there a good way to instrument a plug conn with a function that only gets called just before it gets sent?

Suppose I want to validate my own output and have it crash if it fails to satisfy some schema constraints in dev and test environments.

Hey @ityonemo there is Plug.Conn — Plug v1.12.1

3 Likes

awesome thanks! I swear I looked down that module documentation three times :sweat_smile:

Only gotcha I ran into there is the callback you register won’t be called in the event the client hangs up prematurely. Sounds like that’s fine for your use case, just dropping this comment for folks that find this thread later in case it’s relevant to them :slight_smile:

2 Likes

good catch! I think the only way to trap that is to monitor the handling process.

Look into cowboy stream handlers! I actually think that’s the best way to go personally :slight_smile: It’s worked well for me so far​:crossed_fingers:Bit of a learning curve though.