WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Return 200 when exception is thrown from get method in model

Open ycymio opened this issue 2 years ago • 0 comments

Please correct me if it is a known issue or it is fixed. :)

I created a model and throw the exception in get method. It returns 200 OK with an invalid json body.

{"@odata.context":"https://localhost:44347/odata/$metadata#Products","value":[

Should it return NotImplementedException? As it has started writing response, response code and body cannot be edited.

Assemblies affected

microsoft.aspnetcore.odata version 8.0.4

Reproduce steps

The model I created:

    public class Product
    {
        public int ID
        {
            get { return 1; }
            set { }
        }

        public string Name 
        {
            get 
            {
                throw new NotImplementedException();
            }
            set { }
        }
    }

The program is simple without any middleware.

Expected result

return 500 and throw NotImplementedException.

Actual result

It returns 200 OK with an invalid json body.

{"@odata.context":"https://localhost:44347/odata/$metadata#Products","value":[

Additional detail

ycymio avatar Sep 01 '22 08:09 ycymio