405 responses for image content types

If a service returns a image content type, e.g.

[AddHeader(ContentType = "image/png")]
public Stream Get(ImageRequest request)
   var image = HelperMethod.GetImage();
   if (image == null)
       throw HttpError.NotFound("Image was not found.");

It seems that the HttpError is ignored, and a status code of 405 is returned even though a 404 was requested.

You can see this with the imgur example: http://imgur.servicestack.net/resize/foo

It’s due to there being no registered serializer for serializing Error Responses with that Image Content Type so throws a NotSupportedException. But I’ve changed it to not serialize ErrorResponse bodies for unknown ContentTypes in this commit.

So from v5.1.1 on MyGet it will now return a 404 with no response body.

1 Like