From 6f1dcf3952acea63d944ecd646012b71812bbb93 Mon Sep 17 00:00:00 2001 From: Alda Vigdis Skarphedinsdottir Date: Thu, 18 Jul 2024 14:12:55 +0200 Subject: [PATCH] Stretching the expected response time from the DK API (#167) It seems like during peak periods that DK is not responding to invoice generation requests in time. This stretches the timeout to 10 seconds for GET requests and 15 seconds for POST requests, with is 2x and 3x the default of 5 seconds. --- src/Service/DKApiRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Service/DKApiRequest.php b/src/Service/DKApiRequest.php index cc7b363..91d5d90 100644 --- a/src/Service/DKApiRequest.php +++ b/src/Service/DKApiRequest.php @@ -15,7 +15,9 @@ * Handles the low-level HTTP requests to the DK JSON API. */ class DKApiRequest { - const DK_API_URL = 'https://api.dkplus.is/api/v1'; + const DK_API_URL = 'https://api.dkplus.is/api/v1'; + const GET_TIMEOUT = 10.0; + const POST_TIMEOUT = 15.0; /** * The DK API key @@ -83,6 +85,7 @@ public function get_result( string $path ): WP_Error|stdClass { array( 'httpversion' => '1.1', 'headers' => $this->get_headers, + 'timeout' => self::GET_TIMEOUT, ), ); @@ -117,6 +120,7 @@ public function get_table_result( array( 'httpversion' => '1.1', 'headers' => $this->get_headers, + 'timeout' => self::GET_TIMEOUT, ), ); @@ -155,6 +159,7 @@ public function request_result( 'httpversion' => '1.1', 'headers' => $this->post_headers, 'body' => $body, + 'timeout' => self::POST_TIMEOUT, ), );