Skip to content

Commit

Permalink
handle prometheus error (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
owens1127 authored Jun 5, 2024
1 parent b338445 commit e42a51c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/services/prometheus/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ export const servePrometheus = () => {
Bun.serve({
port: port,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === "/metrics") {
const body = await prometheusRegistry.metrics()
return new Response(body, {
headers: {
"Content-Type": prometheusRegistry.contentType
}
try {
const url = new URL(req.url)
if (url.pathname === "/metrics") {
const body = await prometheusRegistry.metrics()
return new Response(body, {
headers: {
"Content-Type": prometheusRegistry.contentType
}
})
} else {
return new Response(undefined, {
status: 404
})
}
} catch {
return new Response(undefined, {
status: 500
})
}
return new Response(undefined, {
status: 404
})
}
})

Expand Down

0 comments on commit e42a51c

Please sign in to comment.