@@ -10,67 +10,72 @@ import { SkeletonBox } from "@thunderstore/cyberstorm";
1010import { DapperTs } from "@thunderstore/dapper-ts" ;
1111
1212import "./Changelog.css" ;
13+ import { handleLoaderError } from "cyberstorm/utils/errors/handleLoaderError" ;
14+ import { createNotFoundMapping } from "cyberstorm/utils/errors/loaderMappings" ;
15+ import { throwUserFacingPayloadResponse } from "cyberstorm/utils/errors/userFacingErrorResponse" ;
16+ import {
17+ NimbusAwaitErrorElement ,
18+ NimbusDefaultRouteErrorBoundary ,
19+ } from "cyberstorm/utils/errors/NimbusErrorBoundary" ;
20+ import { getLoaderTools } from "cyberstorm/utils/getLoaderTools" ;
1321
1422export async function loader ( { params } : LoaderFunctionArgs ) {
1523 if ( params . namespaceId && params . packageId ) {
16- const publicEnvVariables = getPublicEnvVariables ( [ "VITE_API_URL" ] ) ;
17- const dapper = new DapperTs ( ( ) => {
18- return {
19- apiHost : publicEnvVariables . VITE_API_URL ,
20- sessionId : undefined ,
21- } ;
22- } ) ;
23- return {
24- changelog : dapper . getPackageChangelog (
24+ const { dapper } = getLoaderTools ( ) ;
25+ try {
26+ const changelog = await dapper . getPackageChangelog (
2527 params . namespaceId ,
2628 params . packageId
27- ) ,
28- } ;
29+ ) ;
30+
31+ return {
32+ changelog,
33+ } ;
34+ } catch ( error ) {
35+ handleLoaderError ( error , {
36+ mappings : [
37+ createNotFoundMapping (
38+ "Changelog not available." ,
39+ "We could not find a changelog for this package."
40+ ) ,
41+ ] ,
42+ } ) ;
43+ }
2944 }
30- return {
31- status : "error" ,
32- message : "Failed to load changelog" ,
33- changelog : { html : "" } ,
34- } ;
45+ throwUserFacingPayloadResponse ( {
46+ headline : "Changelog not available." ,
47+ description : "We could not find a changelog for this package." ,
48+ category : "not_found" ,
49+ status : 404 ,
50+ } ) ;
3551}
3652
37- export async function clientLoader ( { params } : LoaderFunctionArgs ) {
53+ export function clientLoader ( { params } : LoaderFunctionArgs ) {
3854 if ( params . namespaceId && params . packageId ) {
39- const tools = getSessionTools ( ) ;
40- const dapper = new DapperTs ( ( ) => {
41- return {
42- apiHost : tools ?. getConfig ( ) . apiHost ,
43- sessionId : tools ?. getConfig ( ) . sessionId ,
44- } ;
45- } ) ;
55+ const { dapper } = getLoaderTools ( ) ;
4656 return {
4757 changelog : dapper . getPackageChangelog (
4858 params . namespaceId ,
4959 params . packageId
5060 ) ,
5161 } ;
5262 }
53- return {
54- status : "error" ,
55- message : "Failed to load changelog" ,
56- changelog : { html : "" } ,
57- } ;
63+ throwUserFacingPayloadResponse ( {
64+ headline : "Changelog not available." ,
65+ description : "We could not find a changelog for this package." ,
66+ category : "not_found" ,
67+ status : 404 ,
68+ } ) ;
5869}
5970
6071export default function Changelog ( ) {
61- const { status, message, changelog } = useLoaderData <
62- typeof loader | typeof clientLoader
63- > ( ) ;
72+ const { changelog } = useLoaderData < typeof loader | typeof clientLoader > ( ) ;
6473
65- if ( status === "error" ) return < div > { message } </ div > ;
6674 return (
6775 < Suspense
6876 fallback = { < SkeletonBox className = "package-changelog__skeleton" /> }
6977 >
70- < Await
71- resolve = { changelog }
72- errorElement = { < div > Error occurred while loading changelog</ div > }
73- >
78+ < Await resolve = { changelog } errorElement = { < NimbusAwaitErrorElement /> } >
7479 { ( resolvedValue ) => (
7580 < >
7681 < div className = "markdown-wrapper" >
@@ -85,3 +90,7 @@ export default function Changelog() {
8590 </ Suspense >
8691 ) ;
8792}
93+
94+ export function ErrorBoundary ( ) {
95+ return < NimbusDefaultRouteErrorBoundary /> ;
96+ }
0 commit comments