repo_description: ⏰ 60s API 免费接口。每天 60 秒看世界、奥运奖牌榜、小红书/B站/微博/抖音/知乎热搜、金价、油价、天气、翻译、壁纸、Epic 游戏、二维码、猫眼票房｜一系列 高质量、开源、可靠、全球 CDN 加速 的开放 API 集合，支持 Docker / Deno / Bun / Cloudflare Workers / Node.js 部署
repo_topics: 60s api bilibili bing bun cloudflare-workers deno docker entertainment fun news today-in-history typescript weibo youdao
code: import { Common } from '../common.ts'
  
  import type { Middleware } from '@oak/oak'
  
  export function handleGlobalError(): Middleware {
    return async (ctx, next) => {
      try {
        await next()
      } catch (err: any) {
        const isJSON = !ctx.state.encoding || ctx.state.encoding === 'json'
        const message = `服务器出错了... ${err?.message || err}`
  
        console.error(err)
  
        ctx.response.status = 500
        ctx.response.body = isJSON ? Common.buildJson(null, 500, message) : message
      }
    }
  }
  