From 39a39238e4ecfd50f1ac89fb85e88bfe85f23c15 Mon Sep 17 00:00:00 2001 From: Timotej Zatko Date: Thu, 10 Sep 2026 17:30:04 +0200 Subject: [PATCH] fix(tombola): stop reporting the jsonp parsererror on every export The tombola service answers /service/tombola-export with a script of its own rather than the jsonp callback jQuery generates - tombola-list does the same, replying with a bare TW_Calc.addTombolaInfo(...) call - so jQuery reports a parsererror for spins the server accepted. The failure handler added in #68 turned each of those into a console error and a /service/send-error report, once per spin. Return early on parsererror with a debug-only log, and drop the error tracking from the handler entirely; a status the export really failed with is still warned about. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01YAUg99g4KbYH58Pk1bSYat --- .../tombola/tombola-exporter.spec.ts | 44 ++++++++++++++++--- src/components/tombola/tombola-exporter.ts | 18 ++++---- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/components/tombola/tombola-exporter.spec.ts b/src/components/tombola/tombola-exporter.spec.ts index d8b4678..43eb2cb 100644 --- a/src/components/tombola/tombola-exporter.spec.ts +++ b/src/components/tombola/tombola-exporter.spec.ts @@ -11,14 +11,19 @@ type Response = Partial; const tombolaId = 60; -/** Minimal stand-in for the jqXHR that `$.get` returns. */ -function fakeJqXHR(): unknown { +/** Minimal stand-in for the jqXHR that `$.get` returns, resolved or rejected with `failStatus`. */ +function fakeJqXHR(failStatus?: string): unknown { const xhr = { done(cb: (resp: unknown) => void) { - cb({ saved: true }); + if (!failStatus) { + cb({ saved: true }); + } return xhr; }, - fail() { + fail(cb: (jqXHR: unknown, textStatus: string, error: unknown) => void) { + if (failStatus) { + cb(undefined, failStatus, new Error(failStatus)); + } return xhr; }, }; @@ -30,6 +35,7 @@ describe('TombolaExporter', () => { let get: jasmine.Spy; let track: jasmine.Spy; + let warn: jasmine.Spy; let wheelPrototype: { process: Function }; /** @@ -37,11 +43,12 @@ describe('TombolaExporter', () => { * `process` hands `response` straight to its callback, which is the seam the exporter * patches itself into, so a call to `spin()` drives the real export path end to end. */ - function setup(event: string, response: Response): void { + function setup(event: string, response: Response, exportFailure?: string): void { const polls: Array<() => void> = []; - get = jasmine.createSpy('get').and.callFake(() => fakeJqXHR()); + get = jasmine.createSpy('get').and.callFake(() => fakeJqXHR(exportFailure)); track = jasmine.createSpy('track'); + warn = jasmine.createSpy('warn'); wheelPrototype = { process(_action: string, _data: WofData, callback: Function, context: WofContext) { @@ -70,7 +77,7 @@ describe('TombolaExporter', () => { getObject: () => ({} as T), setObject: Mock.ANY_FUNC, }).Object, - new Mock({ log: Mock.ANY_FUNC, warn: Mock.ANY_FUNC, error: Mock.ANY_FUNC }).Object, + new Mock({ log: Mock.ANY_FUNC, warn, error: Mock.ANY_FUNC }).Object, new Mock({ website }).Object, new Mock().Object, new Mock({ track, execute: (fn: () => T) => fn() }).Object, @@ -138,4 +145,27 @@ describe('TombolaExporter', () => { expect(exportedSpin()).toEqual({ tombolaId, prize: 54931000, category: 1, level: 25 }); }); + + it('keeps quiet about the parsererror an accepted export answers with', () => { + // the service replies with a script of its own instead of calling the jsonp callback jQuery + // generated, so every exported spin - this one included - is a parsererror to jQuery + setup('Octoberfest', { outcome: { itemId: 54931000, itemEnhance: 25 }, enhance: 25 }, 'parsererror'); + + spin('bribe', { payid: 2 }); + + expect(exportedSpin()).toEqual({ tombolaId, prize: 54931000, category: 1, level: 25 }); + expect(track).not.toHaveBeenCalled(); + expect(warn).not.toHaveBeenCalled(); + }); + + it('warns about an export the server turned down', () => { + // a rejected export is an HTTP error, which the script transport reports as `error` + setup('Octoberfest', { construction_id: 0, itemId: 2354000, itemEnhance: 0 }, 'error'); + + spin('main', { enhance: 0, payid: 2 }); + + expect(warn).toHaveBeenCalled(); + expect(warn.calls.mostRecent().args).toContain('error'); + expect(track).not.toHaveBeenCalled(); + }); }); diff --git a/src/components/tombola/tombola-exporter.ts b/src/components/tombola/tombola-exporter.ts index fc3c621..10fa85b 100644 --- a/src/components/tombola/tombola-exporter.ts +++ b/src/components/tombola/tombola-exporter.ts @@ -201,15 +201,17 @@ export class TombolaExporter implements Component { this.logger.log('tombola exported', resp); }) .fail((_jqXHR, textStatus: string, error: unknown) => { + // The service never calls the jsonp callback jQuery generated - it answers with a + // script of its own (tombola-list replies with a bare `TW_Calc.addTombolaInfo(...)` + // call) - so a spin the server accepted still lands here as a `parsererror`. An + // export the server turns down is an HTTP error, which the script transport reports + // as `error` instead, so only the other statuses are worth a warning. + if (textStatus === 'parsererror') { + this.logger.log('tombola exported', spin); + return; + } + this.logger.warn('unable to export the tombola spin', spin, textStatus, error); - this.errorTracker.track( - InvisibleError.of( - new Error( - `Unable to export the tombola spin! status=${textStatus} ` + `spin=${JSON.stringify(spin)}`, - ), - ), - 'TombolaExporter.exportSpin', - ); }); }