@@ -74,27 +74,32 @@ async function createResoniteApiError(res, type) {
74
74
* @returns
75
75
*/
76
76
async function handle ( type , req , res , next ) {
77
- var apiResponse = await fetch ( getUrl ( type , req ) ) ;
78
- if ( ! apiResponse . ok ) {
79
- var error = await createResoniteApiError ( apiResponse , type ) ;
80
- return next ( error ) ;
77
+ try {
78
+ var apiResponse = await fetch ( getUrl ( type , req ) ) ;
79
+ if ( ! apiResponse . ok ) {
80
+ var error = await createResoniteApiError ( apiResponse , type ) ;
81
+ return next ( error ) ;
82
+ }
83
+
84
+ var json = await apiResponse . json ( ) ;
85
+
86
+ if ( type === "world" && json . recordType !== "world" ) {
87
+ return next ( createError ( 400 , "go.resonite.com only works for Session and world link." ) ) ;
88
+ }
89
+
90
+ if ( type === "sessionList" ) {
91
+ json . title = getOpenGraphTitle ( type ) ;
92
+ }
93
+
94
+ json = preProcess ( json , type ) ;
95
+ json = addMetadata ( type , json ) ;
96
+ json . urlPath = req . getUrl ( ) ;
97
+
98
+ res . status ( 200 ) . render ( type , json ) ;
99
+ } catch ( error ) {
100
+ console . log ( error ) ;
101
+ return next ( createError ( 503 , "Unable to connect to Resonite API, please try again soon." ) ) ;
81
102
}
82
-
83
- var json = await apiResponse . json ( ) ;
84
-
85
- if ( type === "world" && json . recordType !== "world" ) {
86
- return next ( createError ( 400 , "go.resonite.com only works for Session and world link." ) ) ;
87
- }
88
-
89
- if ( type === "sessionList" ) {
90
- json . title = getOpenGraphTitle ( type ) ;
91
- }
92
-
93
- json = preProcess ( json , type ) ;
94
- json = addMetadata ( type , json ) ;
95
- json . urlPath = req . getUrl ( ) ;
96
-
97
- res . status ( 200 ) . render ( type , json ) ;
98
103
}
99
104
100
105
function addMetadata ( pageType , json ) {
@@ -114,29 +119,34 @@ function addMetadata(pageType, json) {
114
119
* @returns
115
120
*/
116
121
async function handleJson ( type , req , res , next ) {
117
- var apiResponse = await fetch ( getUrl ( type , req ) ) ;
118
- if ( ! apiResponse . ok ) {
119
- res . status ( apiResponse . status ) ;
120
- return next ( ) ;
121
- }
122
-
123
- var json = await apiResponse . json ( ) ;
124
122
125
- if ( type === "world" && json . recordType !== "world" ) {
126
- res . status ( 400 ) ;
127
- return next ( ) ;
123
+ try {
124
+ var apiResponse = await fetch ( getUrl ( type , req ) ) ;
125
+ if ( ! apiResponse . ok ) {
126
+ res . status ( apiResponse . status ) ;
127
+ return next ( ) ;
128
+ }
129
+
130
+ var json = await apiResponse . json ( ) ;
131
+
132
+ if ( type === "world" && json . recordType !== "world" ) {
133
+ res . status ( 400 ) ;
134
+ return next ( ) ;
135
+ }
136
+
137
+ json = preProcess ( json , type ) ;
138
+ var title = getOpenGraphTitle ( type ) ;
139
+ res . json ( {
140
+ title : title ,
141
+ author_name : title ,
142
+ author_url : req . getUrl ( ) . replace ( "/json" , "" ) ,
143
+ provider_name : "Resonite" ,
144
+ provider_url : "https://resonite.com" ,
145
+ } ) ;
146
+ } catch ( error ) {
147
+ console . log ( error ) ;
148
+ return next ( createError ( 503 , "Unable to connect to Resonite API, please try again soon." ) ) ;
128
149
}
129
-
130
- json = preProcess ( json , type ) ;
131
- // title is the TOP link
132
- var title = getOpenGraphTitle ( type ) ;
133
- res . json ( {
134
- title : title ,
135
- author_name : title ,
136
- author_url : req . getUrl ( ) . replace ( "/json" , "" ) ,
137
- provider_name : "Resonite" ,
138
- provider_url : "https://resonite.com" ,
139
- } ) ;
140
150
}
141
151
142
152
/**
0 commit comments