add link for redirect in setup module

This commit is contained in:
Lamrani Abdel 2024-03-11 17:31:01 +01:00
parent ec0fd31386
commit 831aee8fa2
2 changed files with 9 additions and 3 deletions

View file

@ -67,7 +67,13 @@ $function = 'textgeneration';
$generatedContent = $ai->generateContent($instructions, 'auto', $function);
if (is_array($generatedContent) && $generatedContent['error']) {
print "Error : " . $generatedContent['message'];
// client errors
if ($generatedContent['code'] >= 400) {
print "Error : " . $generatedContent['message'];
print '<br><a href="'.DOL_MAIN_URL_ROOT.'/ai/admin/setup.php">'.$langs->trans('Check Config of Module').'</a>';
} else {
print "Error : " . $generatedContent['message'];
}
} else {
print $generatedContent;
}

View file

@ -131,7 +131,7 @@ class Ai
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('cURL error: ' . curl_error($ch));
throw new Exception('Wrong configuration !' . curl_error($ch));
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@ -146,7 +146,7 @@ class Ai
return $generatedEmailContent;
} catch (Exception $e) {
return array('error' => true, 'message' => $e->getMessage());
return array('error' => true, 'message' => $e->getMessage(), 'code' => $statusCode);
} finally {
curl_close($ch);
}