Problem/Motivation
When using an NLP Augmentor via the WYSIWYG (but it could probably be for any other usage), timeouts or errors can occur when communicating with the NLP Cloud API. The module logs a 520 error OK, however, it appears that the Augmentor code then goes on to try to access the payload. The resulting error is logged to DBLog.
Warning: Attempt to read property "detail" on null in NLPCloud\NLPCloud->articleGeneration() (line 104 of /code/vendor/nlpcloud/nlpcloud-client/src/NLPCloud.php)
#0 /code/web/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'Attempt to read...', '/code/vendor/nl...', 104)
#1 /code/vendor/nlpcloud/nlpcloud-client/src/NLPCloud.php(104): _drupal_error_handler(2, 'Attempt to read...', '/code/vendor/nl...', 104)
#2 /code/web/modules/contrib/augmentor_nlpcloud/src/Plugin/Augmentor/NLPCloudBlogPostGeneration.php(45): NLPCloud\NLPCloud->articleGeneration('The best books ...')
#3 /code/web/modules/contrib/augmentor/src/Controller/AugmentorController.php(82): Drupal\augmentor_nlpcloud\Plugin\Augmentor\NLPCloudBlogPostGeneration->execute('The best books ...')
#4 [internal function]: Drupal\augmentor\Controller\AugmentorController->execute()
#5 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#6 /code/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#7 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#8 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#9 /code/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#10 /code/vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#11 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /code/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /code/web/modules/contrib/remove_http_headers/src/StackMiddleware/RemoveHttpHeadersMiddleware.php(49): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /code/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /code/web/core/lib/Drupal/Core/DrupalKernel.php(686): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#22 {main}
Steps to reproduce
Access the NLP Cloud API which results in a response error.
Proposed resolution
If there is an error, do not go on the interact with the response.
Remaining tasks
Update the code to make it more defensive.
User interface changes
Possible report back that there was a problem to that an error can be shown to the user. This may be the responsibility of Augmentor WYSIWYG implementation, rather than for NLP Cloud implementation.
API changes
None.
Data model changes
None.