public Stream Read(string type, string id) { IResourceHandler handler = _registry.GetHandler(type); if (handler == null) { return(ErrorMessage(HttpStatusCode.NotImplemented, String.Format("Get resource of type {0} not implemented.", type))); } try { string payload = handler.Read(id); if (String.IsNullOrEmpty(payload)) { return(ErrorMessage(HttpStatusCode.NotFound, String.Format("{1} resource {0} not found", id, type))); } return(new MemoryStream(Encoding.UTF8.GetBytes(payload))); } catch (Exception e) { if (e.GetType() == typeof(NotImplementedException)) { return(ErrorMessage(HttpStatusCode.NotImplemented, e.Message)); } return(ErrorMessage(HttpStatusCode.InternalServerError, e.Message)); } }