Home > front end >  Webhook receiver response
Webhook receiver response

Time:09-30

I have a Webhook receiver with aspnet webapi and use this packages

Microsoft.AspNet.WebHooks.Common
Microsoft.AspNet.WebHooks.Receivers
Microsoft.AspNet.WebHooks.Receivers.Generic

And this is my handler

Public Class GenericJsonWebHookHandler
    Inherits WebHookHandler

    Public Sub New()
        Me.Receiver = GenericJsonWebHookReceiver.ReceiverName
    End Sub

    Public Overrides Function ExecuteAsync(ByVal receiver As String, ByVal context As WebHookHandlerContext) As Task
        Dim data As JObject = context.GetDataOrDefault(Of JObject)()
        If data.HasValues Then
            'Do something
            Return Task.FromResult(True)
        Else
            'Here I want to return a Bad Request or a different that 200 OK
        End If
    End Function
End Class

I want make some verification with the json I recieve and if fails I need to return a differente status that 200 OK, How can I do it?

CodePudding user response:

It was very easy, if someone have the same problem here it is:

context.Response = context.Request.CreateResponse(HttpStatusCode.BadRequest, "Some message")
Return Task.FromResult(True)
  • Related