I use two approaches. The harder but more versarile approach is to distribute and spawn a custom webserver that exhibits the intended (error) behaviours under well-known URLs. See
WWW::Mechanize and
WWW::Mechanize::Firefox for examples of that. The other approach is to use
fike:// URIs in the strategic places to return (broken) content with status 200 (or 404 for "not found").