Handle API error more gracefully

This commit is contained in:
Dimitri Lozeve 2022-09-20 21:40:03 +02:00
parent e223a736e1
commit fb6cc611c7
4 changed files with 44 additions and 26 deletions

View file

@ -45,15 +45,21 @@
(displayln (if (null? messages) "[Pas de message]" (hash-ref (car messages) 'text))))))
(def (display-all departures disruptions station-name (datetime #f) style: (style 'unicode))
(display
(if (eq? style 'markdown)
(format "Prochains départs de **~a** " station-name)
(parse-markup
(format "[bold]Prochains départs de [green]~a[/green] " station-name))))
(when datetime
(display (format "le ~a à ~a "
(date->string datetime "~d ~b ~Y")
(date->string datetime "~H:~M"))))
(displayln (if (eq? style 'markdown) ":\n" ":"))
(display-departures-table departures style: style)
(display-disruptions disruptions style: style))
(let/cc return
(unless departures
(displayln (format "Aucun départ prévu de ~a~a"
station-name
(if datetime (string-append " le " (date->string datetime "~d ~b ~Y")))))
(return))
(display
(if (eq? style 'markdown)
(format "Prochains départs de **~a** " station-name)
(parse-markup
(format "[bold]Prochains départs de [green]~a[/green] " station-name))))
(when datetime
(display (format "le ~a à ~a "
(date->string datetime "~d ~b ~Y")
(date->string datetime "~H:~M"))))
(displayln (if (eq? style 'markdown) ":\n" ":"))
(display-departures-table departures style: style)
(display-disruptions disruptions style: style)))