Agrarmonitor #2

Merged
bjoernpoettker merged 21 commits from Agrarmonitor into main 2026-05-25 11:02:59 +00:00
2 changed files with 13 additions and 2 deletions
Showing only changes of commit 74cd2477f1 - Show all commits
@@ -105,9 +105,8 @@ export class AgrarmonitorPollingService implements OnModuleInit {
)) {
try {
const lieferantennummer = (customer['lieferantennummer'] as string) ?? '';
const searchName = `(${lieferantennummer})`;
const displayName = this.buildCustomerName(customer, lieferantennummer);
const existing = await this.paperlessService.getCorrespondentByName(searchName);
const existing = await this.paperlessService.getCorrespondentByName(displayName);
if (!existing) {
await this.paperlessService.addCorrespondent({
name: displayName,
@@ -153,6 +152,14 @@ export class AgrarmonitorPollingService implements OnModuleInit {
try {
amResults = await amClient.eingangsrechnungenLivesearch(interneBelegnummer);
} 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`;
this.logger.error(`${msg}: ${err instanceof Error ? err.message : err}`);
result.errors.push(msg);
@@ -56,6 +56,10 @@ export class AgrarmonitorService {
return this.client;
}
clearClient(): void {
this.client = null;
}
async getStatus(): Promise<AgrarmonitorStatusDto> {
try {
const client = await this.getClient();