fix: two polling bugs — correspondent 400 and Agrarmonitor 403
Build and Push Multi-Platform Images / build-and-push (push) Successful in 30s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 30s
- 400 on Korrespondenten-Sync: getCorrespondentByName was called with searchName "(12345)" but checked exact match against full displayName "Firma (12345)". Always returned null → duplicate addCorrespondent on every run → Paperless 400. Fix: search by displayName directly. - 403 on Livesearch: cached Agrarmonitor session expired. Fix: detect 401/403 from connector, call clearClient() to invalidate cache, break out of the polling loop so next cron run re-authenticates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -105,9 +105,8 @@ export class AgrarmonitorPollingService implements OnModuleInit {
|
|||||||
)) {
|
)) {
|
||||||
try {
|
try {
|
||||||
const lieferantennummer = (customer['lieferantennummer'] as string) ?? '';
|
const lieferantennummer = (customer['lieferantennummer'] as string) ?? '';
|
||||||
const searchName = `(${lieferantennummer})`;
|
|
||||||
const displayName = this.buildCustomerName(customer, lieferantennummer);
|
const displayName = this.buildCustomerName(customer, lieferantennummer);
|
||||||
const existing = await this.paperlessService.getCorrespondentByName(searchName);
|
const existing = await this.paperlessService.getCorrespondentByName(displayName);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
await this.paperlessService.addCorrespondent({
|
await this.paperlessService.addCorrespondent({
|
||||||
name: displayName,
|
name: displayName,
|
||||||
@@ -153,6 +152,14 @@ export class AgrarmonitorPollingService implements OnModuleInit {
|
|||||||
try {
|
try {
|
||||||
amResults = await amClient.eingangsrechnungenLivesearch(interneBelegnummer);
|
amResults = await amClient.eingangsrechnungenLivesearch(interneBelegnummer);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
const status = (err as any)?.response?.status;
|
||||||
|
if (status === 401 || status === 403) {
|
||||||
|
this.agrarmonitorService.clearClient();
|
||||||
|
const msg = `Session abgelaufen (${status}) — Polling abgebrochen, nächster Lauf meldet sich neu an`;
|
||||||
|
this.logger.warn(msg);
|
||||||
|
result.errors.push(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
const msg = `${interneBelegnummer}: Livesearch-Fehler`;
|
const msg = `${interneBelegnummer}: Livesearch-Fehler`;
|
||||||
this.logger.error(`${msg}: ${err instanceof Error ? err.message : err}`);
|
this.logger.error(`${msg}: ${err instanceof Error ? err.message : err}`);
|
||||||
result.errors.push(msg);
|
result.errors.push(msg);
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ export class AgrarmonitorService {
|
|||||||
return this.client;
|
return this.client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearClient(): void {
|
||||||
|
this.client = null;
|
||||||
|
}
|
||||||
|
|
||||||
async getStatus(): Promise<AgrarmonitorStatusDto> {
|
async getStatus(): Promise<AgrarmonitorStatusDto> {
|
||||||
try {
|
try {
|
||||||
const client = await this.getClient();
|
const client = await this.getClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user