Handle bad URIs gracefully

Based on @xaviershay's change, modified to return 400 instead of 404 and to provide a `Content-Type`.