Skip to content

Commit f548820

Browse files
committed
Improve error handling in remaining components
1 parent cfa9798 commit f548820

7 files changed

Lines changed: 638 additions & 363 deletions

File tree

‎src/components/Footer/client.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import { LoadableScript, type TriggerEvent } from '../Scripts/loader/@types/loader'
55
import { getHireMeAnchorElement } from './selectors'
6+
import { handleScriptError, addScriptBreadcrumb } from '@components/Scripts/errors'
67

78
class Footer extends LoadableScript {
89
static override scriptName = 'Footer'
@@ -15,12 +16,20 @@ class Footer extends LoadableScript {
1516
}
1617

1718
static override init(): void {
18-
const anchor = getHireMeAnchorElement()
19-
const date = new Date()
20-
const month = Footer.getMonthName(date)
21-
const year = date.getFullYear()
22-
anchor.innerHTML = `Available ${month}, ${year}. Hire Me Now`
23-
anchor.style.display = 'inline-block'
19+
const context = { scriptName: Footer.scriptName, operation: 'init' }
20+
addScriptBreadcrumb(context)
21+
22+
try {
23+
const anchor = getHireMeAnchorElement()
24+
const date = new Date()
25+
const month = Footer.getMonthName(date)
26+
const year = date.getFullYear()
27+
anchor.innerHTML = `Available ${month}, ${year}. Hire Me Now`
28+
anchor.style.display = 'inline-block'
29+
} catch (error) {
30+
// Footer date is optional enhancement
31+
handleScriptError(error, context)
32+
}
2433
}
2534

2635
static override pause(): void {

‎src/components/Hero/client.ts‎

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LoadableScript, type TriggerEvent } from '../Scripts/loader'
22
import { gsap } from 'gsap'
3+
import { handleScriptError, addScriptBreadcrumb } from '@components/Scripts/errors'
34

45
type Timeline = ReturnType<typeof gsap.timeline>
56

@@ -39,15 +40,19 @@ export class HeroLoader extends LoadableScript {
3940
}
4041

4142
private startAnimation() {
42-
if (document.getElementById('heroAnimation') == undefined) return
43+
const context = { scriptName: HeroLoader.scriptName, operation: 'startAnimation' }
44+
addScriptBreadcrumb(context)
4345

44-
if (this.timeline) {
45-
return
46-
}
46+
try {
47+
if (document.getElementById('heroAnimation') == undefined) return
4748

48-
gsap.set('.monitorBottom', {
49-
transformOrigin: '50% 100%',
50-
})
49+
if (this.timeline) {
50+
return
51+
}
52+
53+
gsap.set('.monitorBottom', {
54+
transformOrigin: '50% 100%',
55+
})
5156

5257
gsap.set(['.monitorStand', '.laptopBase', '.tabletScreen'], {
5358
transformOrigin: '50% 0%',
@@ -385,30 +390,63 @@ export class HeroLoader extends LoadableScript {
385390
delay: 2,
386391
ease: 'back.in(2)',
387392
})
393+
} catch (error) {
394+
// Animation is optional enhancement - handle gracefully
395+
handleScriptError(error, context)
396+
}
388397
}
389398

390399
static override init() {
391-
if (!HeroLoader.instance) {
392-
HeroLoader.instance = new HeroLoader()
400+
const context = { scriptName: HeroLoader.scriptName, operation: 'init' }
401+
addScriptBreadcrumb(context)
402+
403+
try {
404+
if (!HeroLoader.instance) {
405+
HeroLoader.instance = new HeroLoader()
406+
}
407+
HeroLoader.instance.startAnimation()
408+
} catch (error) {
409+
// Animation is optional - page still works without it
410+
handleScriptError(error, context)
393411
}
394-
HeroLoader.instance.startAnimation()
395412
}
396413

397414
static override pause() {
398-
if (HeroLoader.instance?.timeline) {
399-
HeroLoader.instance.timeline.pause()
415+
const context = { scriptName: HeroLoader.scriptName, operation: 'pause' }
416+
addScriptBreadcrumb(context)
417+
418+
try {
419+
if (HeroLoader.instance?.timeline) {
420+
HeroLoader.instance.timeline.pause()
421+
}
422+
} catch (error) {
423+
handleScriptError(error, context)
400424
}
401425
}
402426

403427
static override resume() {
404-
if (HeroLoader.instance?.timeline) {
405-
HeroLoader.instance.timeline.play()
428+
const context = { scriptName: HeroLoader.scriptName, operation: 'resume' }
429+
addScriptBreadcrumb(context)
430+
431+
try {
432+
if (HeroLoader.instance?.timeline) {
433+
HeroLoader.instance.timeline.play()
434+
}
435+
} catch (error) {
436+
handleScriptError(error, context)
406437
}
407438
}
408439

409440
static override reset() {
410-
if (HeroLoader.instance?.timeline) {
411-
HeroLoader.instance.timeline.restart()
441+
const context = { scriptName: HeroLoader.scriptName, operation: 'reset' }
442+
addScriptBreadcrumb(context)
443+
444+
try {
445+
if (HeroLoader.instance?.timeline) {
446+
HeroLoader.instance.timeline.restart()
447+
}
448+
} catch (error) {
449+
handleScriptError(error, context)
412450
}
413451
}
414452
}

0 commit comments

Comments
 (0)