Improve CVR lookup error handling and unify phone number registration error messages
This commit is contained in:
@@ -416,7 +416,7 @@ class authRoute
|
||||
|
||||
if ($matchingEconomicCustomer !== null) {
|
||||
if ($localUserExists) {
|
||||
$response->error('Company phone number already registered 01', 400);
|
||||
$response->error('Company phone number already registered', 400);
|
||||
}
|
||||
|
||||
$this->bootstrapLocalCustomerOrFail($companyPhone);
|
||||
@@ -441,12 +441,35 @@ class authRoute
|
||||
}
|
||||
|
||||
if ($localUserExists) {
|
||||
$response->error('Company phone number already registered 02', 400);
|
||||
$response->error('Company phone number already registered', 400);
|
||||
}
|
||||
|
||||
// Get the CVR company information used for the e-conomic customer payload.
|
||||
$companyInformation = (new virkdata())->getCompanyInformation($cvr, '', []);
|
||||
$name = (string)($companyInformation->name ?? '');
|
||||
$companyInformation = null;
|
||||
try {
|
||||
$companyInformation = (new virkdata())->getCompanyInformation((string)$cvr, '', []);
|
||||
} catch (Exception $exception) {
|
||||
$this->logRegisterCvrIssue('AUTH_REGISTER_CVR_LOOKUP_FAILED', [
|
||||
'phase' => 'cvr_lookup',
|
||||
'cvr' => (string)$cvr,
|
||||
'requestedCustomerNumber' => $companyPhone,
|
||||
'message' => $exception->getMessage(),
|
||||
]);
|
||||
$response->error('CVR could not be verified. Please check the CVR number and try again.', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim((string)($companyInformation->name ?? ''));
|
||||
if ($name === '') {
|
||||
$this->logRegisterCvrIssue('AUTH_REGISTER_CVR_LOOKUP_INVALID_RESPONSE', [
|
||||
'phase' => 'cvr_lookup',
|
||||
'cvr' => (string)$cvr,
|
||||
'requestedCustomerNumber' => $companyPhone,
|
||||
]);
|
||||
$response->error('CVR could not be verified. Please check the CVR number and try again.', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $economic->createCustomer(
|
||||
(int)$companyPhone,
|
||||
@@ -765,7 +788,7 @@ class authRoute
|
||||
private function localCustomerNumberExists(int $customerNumber): bool
|
||||
{
|
||||
$rows = (new users_o())->getFieldsWhere([
|
||||
'customer_number' => (int)$customerNumber,
|
||||
'customer_number' => (string)$customerNumber,
|
||||
], ['id']);
|
||||
|
||||
return count($rows) > 0;
|
||||
|
||||
Reference in New Issue
Block a user