tcWebHooks icon indicating copy to clipboard operation
tcWebHooks copied to clipboard

Show response body for failed request

Open YoungjaeKim opened this issue 7 years ago • 13 comments

Expected Behavior

In order to investigate failed webhook easily, it would be good to show response.content if possible.

Current Behavior

Currently, only status code is displayed. As you know, Bad Request usually contains error message in content.

image

Steps to Reproduce (for bugs)

N/A

Your Environment

  • tcWebHooks Version: 1.1-alpha17.235.354
  • TeamCity Version: 2018.1.1 (build 58406)
  • TeamCity server Operating System: Ubuntu 16 LTS
  • Are you using a WebHook Template?: Yes

Example Configuration (xml)

I can provide it if you needed to.

YoungjaeKim avatar Sep 26 '18 11:09 YoungjaeKim

Might be useful just to store response for any result.

netwolfuk avatar Sep 30 '18 12:09 netwolfuk

I'm running into issues where I can't figure out why my webhook isn't working, and it would be helpful to see both the request and the response in even the debug logs on the server. This would go a long way in figuring out why I'm getting a particular code.

kymikoloco avatar Oct 10 '18 21:10 kymikoloco

Of course! If you're happy with debug logging as an interim solution, I'll try to add that and get rc2 out in the next day or so.

netwolfuk avatar Oct 11 '18 05:10 netwolfuk

Hi @kymikoloco and @YoungjaeKim I have added debug logging of the payload to the webhook processor. In my unit tests, it sometimes shows the payload, or if it can't be converted to a String, will print the object reference, so I would like to do some more testing before I release RC2.

However, here is a build which has the added DEBUG logging. You can login as a guest on that teamcity instance to download the zip files. Please let me know how you get on. The output in the log looks like this (although it may change)

    DEBUG SERVER:37 - WebHookImpl::  --- Begin Server Response --- 
    DEBUG SERVER:37 - <h1>Hello SimpleServlet</h1>
    DEBUG SERVER:37 - WebHookImpl::  --- End Server Response ---

I will also look at adding the logging of all the response headers. This are currently not shown in the log.

To enable debug logging in teamcity, see this page.

netwolfuk avatar Oct 12 '18 10:10 netwolfuk

@netwolfuk Just installed the build, and the server logs are printing the response headers, so it works for me. Though now, the server response says that an argument 'type' is missing when it is being sent. Should I make a new issue for this?

[2018-10-12 14:26:18,961]  DEBUG -   jetbrains.buildServer.SERVER - #### CONTENT #### {
    "@type": "private",
    "to": "[email protected]",
    "content": "Build successful - Build & Install :: Success"
}
[2018-10-12 14:26:19,953]  DEBUG -   jetbrains.buildServer.SERVER - WebHookImpl::  --- Begin Server Response ---
[2018-10-12 14:26:19,953]  DEBUG -   jetbrains.buildServer.SERVER - {"var_name":"type","result":"error","code":"REQUEST_VARIABLE_MISSING","msg":"Missing 'type' argument"}
[2018-10-12 14:26:19,953]  DEBUG -   jetbrains.buildServer.SERVER - WebHookImpl::  --- End Server Response ---

kymikoloco avatar Oct 12 '18 18:10 kymikoloco

Hi @kymikoloco I'm not sure what format the server is expecting, but it looks like it wants a variable called type in the webhook payload. It looks like you have that already, but I'm not sure what the @ means in the payload. I would suggest double checking that the data you are sending is what the server expects. What service are you sending the webhook to? Are you using on of the bundled templates, or did you create your own one?

netwolfuk avatar Oct 12 '18 20:10 netwolfuk

I'm attempting to use this API: https://zulipchat.com/api/private-message and I created my own template.

The '@type' I took from the Microsoft Teams template, thinking the type was getting lost somewhere, or was getting mistaken for Content-Type and being consumed somehow, but with or without the @ it comes back with the same error message.

curl works with x-www-form-urlencoded, but attempting to use application/json, it fails the same way as tcWebHooks, with a BadRequest (400). It seems like the API endpoint I'm using is not robust enough to accept JSON for API requests.

kymikoloco avatar Oct 12 '18 22:10 kymikoloco

Ok, that's good debugging. Well done.

It should be possible to create a new template type to support x-www-form-urlencoded just like #119 does for application/xml. It would be a bit more complicated though I think.

netwolfuk avatar Oct 12 '18 22:10 netwolfuk

BTW, if I remember correctly x-www-form-urlencoded is kinda just the parameters URL encoded in the body.

So something like this might work in your template (as long as you provide a Content-Type header)

As per https://zulipchat.com/api/send-message

type=private&[email protected]&content=I+come+not,+friends,+to+steal+away+your+hearts

netwolfuk avatar Oct 12 '18 23:10 netwolfuk

Or you could create a legacy nvpairs webhook and create build parameters called webhook.type, etc.

The webhook will also post a ton of other cruft, but as long as the end point is only looking for those items, it might work.

BTW, from version 2.0, the legacy webhook formats will only send the requested fields, not everything by default.

netwolfuk avatar Oct 12 '18 23:10 netwolfuk

See https://netwolfuk.wordpress.com/2014/09/22/building-tcwebhooks-custom-parameters-from-teamcity-build-parameters/

netwolfuk avatar Oct 12 '18 23:10 netwolfuk

Using the legacy nvpairs with the build parameters works! I'll probably revisit it later as it's not the most user friendly way to send a message, but I'm glad it works, thanks!

kymikoloco avatar Oct 15 '18 22:10 kymikoloco

You could also move the build parameters to the project level, and they will be inherited by the builds. But, yeah. Can you add a new issue to add a x-www-form-urlencoded template?

netwolfuk avatar Oct 15 '18 23:10 netwolfuk