If you wanted to make it more resilient,, make the request, check if OK, check if JSON, and then cal
If you wanted to make it more resilient,, make the request, check if OK, check if JSON, and then call
.json().json()properties.periods doesn't exist, for example..ok and also check if the content-type includes application/json. You'd be surprised at how many APIs are wonky sometimes and return a 200 but an HTML error page or something.properties doesn't exist there, you'll get a TypeError. I'd check proto_res.properties exists tooif(!proto_res?.properties?.periods) with optional chaining.properties.periods would throw a TypeError if properties doesn't exist. For example:
performance.now() isn’t available in Workers and Date.now() doesn’t increment unless you do I/O is there any way to actually benchmark CPU bound function execution times in a worker?performance.now() is available but it just calls Date.now()internal server error anyplace to look to see better logging?app.onError to add your own handlerproduction stuff on the dashboard entirely right now
properties.periods.okapplication/json.propertiesTypeErrorTypeErrorproto_res.propertiesif(!proto_res?.properties?.periods).properties.periodsperformance.now()performance.now()Date.now()Date.now()internal server errorapp.onErrorproduction[placement]
mode = "smart"if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}/hourly`);const fetch_headers = {
'User-Agent': `${fitweather_credentials.name}/1.0 (Florida Institute of Technology Weather Discord Bot (Student Run), https://github.com/DaBigBlob/FIT-Weather-Chan)`,
'Accept': "application/geo+json"
};export function exists<T>(data: T|null|undefined): data is T {
if (
(data === null) ||
(data === undefined)
) return false;
return true;
}const obj = {foo: 'bar'}
console.log(obj.foo) // bar
console.log(obj.bar) // undefined
console.log(obj.bar.baz) // TypeErrorimport { Hono } from 'hono'
import { Client } from 'pg'
const app = new Hono()
const connstring = "postgresql://postgres@localhost:5432/hhscdev?schema=public"
app.get('*', async (c) => {
const client = new Client("postgresql://postgres@localhost:5432/hhscdev?schema=public");
await client.connect();
const { rows: [{ now }] } = await client.query('select now();');
return c.text(`Hello Hono! ${now}`)
})
export default app