P. Naber
P. Naber

Reputation: 75

Azure Mobile Service with .NET Backend get exception

When adding an entity with a child entity (1:n) I'm getting an exception. I can only get this exception when the debugger is catching all exceptions. Unfortunately only the message of the exception is visible and not the exception itself with the information I need. (System.Data.Entity.Validation.DbEntityValidationException) (when inserting an entity without childs the service works correct)

The client gets a MobileServiceInvalidOperationException: The request could not be completed. (Bad Request)

The method on the controller (PatchAppointment) is the only method where I can add exceptionhandling and the exception is not coming in here.

 public Task<Appointment> PatchAppointment(string id, Delta<Appointment> patch)
    {
        try
        {
            return UpdateAsync(id, patch);
        }
        catch (Exception ex)
        {
            // not coming through here..
            throw;
        }             
    }

I also tried adding an ExceptionLogger to the Httpconfiguration.Services but no exception is coming in.

How should I get the whole exception object to see the EntityValidationErrors? When this is known I can also add logging when exceptions occur.

Upvotes: 1

Views: 479

Answers (1)

Reza Jooyandeh
Reza Jooyandeh

Reputation: 761

What do you mean by "PatchAppointment in the only method" that you can add exception handling? If you have trouble inserting you have to check PostAppointment not PatchAppointment. PatchAppointment deals with updating data while you mentioned that you have trouble inserting into your table.

public async Task<IHttpActionResult> PostAppointment(Appointment item)
{
    Appointment current = await InsertAsync(item);
    return CreatedAtRoute("Tables", new { id = current.Id }, current);
}

Upvotes: 1

Related Questions