Azure Function - Not throwing right exception; always throws Internal Server error

Kothai Ramanathan 941 Reputation points Microsoft Employee
2021-01-21T10:39:05.183+00:00

I have a ADF Azure Function activity which calls an Azure Function. In the Azure Function, this is my exception block.

        catch (Exception exception)
        {
            log.LogError($"SelfServeProcess failed with an exception. Error: {exception.Message} StackTrace: {exception.StackTrace}");
            throw exception;
        }

I see the right exception/message being caught. But instead of throwing the right exception/message, the Azure Function is always throwing InternalServerError.
How can I make the Azure Function throw the right original exception ?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,357 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nasreen Akter 10,761 Reputation points
    2021-01-21T13:14:14.297+00:00

    Hi @Kothai Ramanathan ,

    The error block looks good to me. In the main function, you can try the following. Thanks!

    catch (Exception exception)  
    {  
       JObject error = new JObject();  
       error.Add("error", exception.Message);  
       log.LogError($"SelfServeProcess failed with an exception. Error: {exception.Message} StackTrace: {exception.StackTrace}");  
       return new BadRequestObjectResult(error);  
    }   
    

    ----------

    If the above response helps, please "accept as answer" and "up-vote" the same! Thanks!

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful