Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws 500 error for gitlab urls returning 404s #9

Open
gabrielgrant opened this issue Apr 16, 2020 · 3 comments
Open

Throws 500 error for gitlab urls returning 404s #9

gabrielgrant opened this issue Apr 16, 2020 · 3 comments

Comments

@gabrielgrant
Copy link

Thanks for this awesome app, makes using gitlab sooo much better with slack!

Fairly minor issue, but it seems the plugin throws an error, causing a 500 to be returned, when it tries to check a gitlab URL that results in a 404:

Full traceback
[2020-04-16 09:24:06] unfurl.DEBUG: link_shared {"event":{"type":"link_shared","user":"...redacted...","channel":"...redacted...","message_ts":"1587053875.000600","links":[{"url":"https://gitlab.com/something/that/doesnt/exist","domain":"gitlab.com"},{"url":"https://gitlab.com/something/that/doesnt/exist","domain":"gitlab.com"}],"event_ts":"1587053876.981069"}} []
[2020-04-16 09:24:06] unfurl.CRITICAL: Gitlab\Exception\RuntimeException: 404 Not found (uncaught exception) at /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php line 50 {"exception":"[object] (Gitlab\\Exception\\RuntimeException(code: 404): 404 Not found at /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php:50)"} []
[2020-04-16 09:24:06] unfurl.ERROR: 404 Not found {"exception":"[object] (Gitlab\\Exception\\RuntimeException(code: 404): 404 Not found at /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php:50)","trace":"#0 /home/bbread/slack-unfurl/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(34): Gitlab\\HttpClient\\Plugin\\GitlabExceptionThrower->Gitlab\\HttpClient\\Plugin\\{closure}(Object(GuzzleHttp\\Psr7\\Response))\n#1 /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Plugin/GitlabExceptionThrower.php(54): Http\\Client\\Promise\\HttpFulfilledPromise->then(Object(Closure))\n#2 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/Plugin/VersionBridgePlugin.php(19): Gitlab\\HttpClient\\Plugin\\GitlabExceptionThrower->doHandleRequest(Object(GuzzleHttp\\Psr7\\Request), Object(Closure), Object(Closure))\n#3 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/PluginClient.php(161): Gitlab\\HttpClient\\Plugin\\GitlabExceptionThrower->handleRequest(Object(GuzzleHttp\\Psr7\\Request), Object(Closure), Object(Closure))\n#4 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/PluginClient.php(175): Http\\Client\\Common\\PluginClient->Http\\Client\\Common\\{closure}(Object(GuzzleHttp\\Psr7\\Request))\n#5 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/PluginClient.php(88): Http\\Client\\Common\\PluginClient->Http\\Client\\Common\\{closure}(Object(GuzzleHttp\\Psr7\\Request))\n#6 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/HttpMethodsClient.php(208): Http\\Client\\Common\\PluginClient->sendRequest(Object(GuzzleHttp\\Psr7\\Request))\n#7 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/HttpMethodsClient.php(194): Http\\Client\\Common\\HttpMethodsClient->sendRequest(Object(GuzzleHttp\\Psr7\\Request))\n#8 /home/bbread/slack-unfurl/vendor/php-http/client-common/src/HttpMethodsClient.php(66): Http\\Client\\Common\\HttpMethodsClient->send('GET', 'projects/gabrie...', Array, NULL)\n#9 /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/AbstractApi.php(66): Http\\Client\\Common\\HttpMethodsClient->get('projects/gabrie...', Array)\n#10 /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/AbstractApi.php(77): Gitlab\\Api\\AbstractApi->getAsResponse('projects/gabrie...', Array, Array)\n#11 /home/bbread/slack-unfurl/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/MergeRequests.php(104): Gitlab\\Api\\AbstractApi->get('projects/gabrie...')\n#12 /home/bbread/slack-unfurl/vendor/glen/slack-unfurl-gitlab/src/Route/MergeRequest.php(9): Gitlab\\Api\\MergeRequests->show('gabrielgrant/br...', '62')\n#13 /home/bbread/slack-unfurl/vendor/glen/slack-unfurl-gitlab/src/Route/AbstractRouteHandler.php(43): GitlabSlackUnfurl\\Route\\MergeRequest->getDetails(Array)\n#14 /home/bbread/slack-unfurl/vendor/glen/slack-unfurl-gitlab/src/Event/Subscriber/GitlabUnfurler.php(78): GitlabSlackUnfurl\\Route\\AbstractRouteHandler->unfurl('https://gitlab....', Array)\n#15 /home/bbread/slack-unfurl/vendor/glen/slack-unfurl-gitlab/src/Event/Subscriber/GitlabUnfurler.php(60): GitlabSlackUnfurl\\Event\\Subscriber\\GitlabUnfurler->unfurlByUrl('https://gitlab....')\n#16 /home/bbread/slack-unfurl/vendor/symfony/event-dispatcher/EventDispatcher.php(264): GitlabSlackUnfurl\\Event\\Subscriber\\GitlabUnfurler->unfurl(Object(SlackUnfurl\\Event\\UnfurlEvent), 'slack.unfurl', Object(Symfony\\Component\\EventDispatcher\\EventDispatcher))\n#17 /home/bbread/slack-unfurl/vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(Array, 'slack.unfurl', Object(SlackUnfurl\\Event\\UnfurlEvent))\n#18 /home/bbread/slack-unfurl/vendor/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\\Component\\EventDispatcher\\EventDispatcher->callListeners(Array, 'slack.unfurl', Object(SlackUnfurl\\Event\\UnfurlEvent))\n#19 /home/bbread/slack-unfurl/src/Command/LinkShared.php(43): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch(Object(SlackUnfurl\\Event\\UnfurlEvent), Object(SlackUnfurl\\Event\\UnfurlEvent))\n#20 /home/bbread/slack-unfurl/src/Command/EventCallback.php(34): SlackUnfurl\\Command\\LinkShared->execute(Array)\n#21 /home/bbread/slack-unfurl/src/Controller/UnfurlController.php(44): SlackUnfurl\\Command\\EventCallback->execute(Array)\n#22 /home/bbread/slack-unfurl/src/Application.php(42): SlackUnfurl\\Controller\\UnfurlController->__invoke(Object(Symfony\\Component\\HttpFoundation\\Request))\n#23 /home/bbread/slack-unfurl/vendor/symfony/http-kernel/HttpKernel.php(158): SlackUnfurl\\Application->SlackUnfurl\\{closure}(Object(Symfony\\Component\\HttpFoundation\\Request))\n#24 /home/bbread/slack-unfurl/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#25 /home/bbread/slack-unfurl/vendor/silex/silex/src/Silex/Application.php(496): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#26 /home/bbread/slack-unfurl/vendor/silex/silex/src/Silex/Application.php(477): Silex\\Application->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#27 /home/bbread/gitlab-slack-unfurler.breakingbreadnow.com/index.php(4): Silex\\Application->run()\n#28 {main}"} []
[2020-04-16 09:24:06] unfurl.DEBUG: < 500 [] []

The end result is that the link is just not unfurled in slack, which isn't terrible, but would maybe be nice to catch this and show some message about the link being inaccessible (and possibly wrong?)

@glensc
Copy link
Owner

glensc commented Apr 18, 2020

GitLab.com redirects to Sign In page when not logged in:

image

Do you have example JSON to give to 404 responses?

My idea was to add more handlers specific to the content, like on the pipeline URL give some details on pipelines. but never got that implemented, and contributions aren't exactly flooding in either :)

@glensc
Copy link
Owner

glensc commented Apr 18, 2020

But what URL you tested with? Looks like it made gitlab API query and failed, so it wasn't totally 404 URL, but related to some project?

As I'm thinking about the code logic, it shouldn't make API calls to routes that are not handled.

@gabrielgrant
Copy link
Author

gabrielgrant commented Apr 18, 2020

I believe I came across this when I pasted a URL that pointed to an issue in an existing project, but then accidentally changed the number to one that didn't exist

Edit: just confirmed -- yes, that does seem to trigger it

So it's not so surprising that the URL isn't unfurled, but returning an unfurl response that says something about the page not existing would be helpful. At the moment, because nothing is shown at all, we thought the unfurler just wasn't working. Wasn't until I went digging into the logs and saw the 404 that i realized i'd just fat-fingered the URL :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants