hcengineering/platform · error · HttpError
Internal Server Error
Error message
Internal Server Error
What it means
The link-preview pod's errorHandler is the final middleware: for errors that carry a numeric err.code it echoes that status, but for anything else it calls Analytics.handleError and returns HTTP 500 with err.message ?? 'Internal Server Error'. So this message is the fallback for any unexpected exception thrown by link-preview request handling.
Source
Thrown at pods/link-preview/src/middleware.ts:72
export interface ErrorHandlerOptions {
ctx: MeasureContext
}
export const errorHandler = (options: ErrorHandlerOptions): ErrorRequestHandler => {
const { ctx } = options
return (err: any, req: Request, res: Response, _next: NextFunction): void => {
ctx.error(err.message, { code: err.code, message: err.message })
if (err instanceof HttpError) {
res.status(err.code).json({ message: err.message })
return
}
Analytics.handleError(err)
res.status(500).json({ message: err.message ?? 'Internal Server Error' })
}
}
View on GitHub (pinned to 63e28dc964)
Solutions
- Check server logs / Analytics for the underlying error recorded by Analytics.handleError to find the real cause
- Verify the target URL is reachable from the server (firewall, DNS, TLS) — not just from your browser
- Retry the request; transient fetch/parse failures of the target page are the most common cause
- If reproducible for one URL, inspect that page's markup for parser-breaking content and report/upgrade the preview parser
Example fix
// before
res.status(500).json({ message: err.message ?? 'Internal Server Error' })
// after (caller side)
try {
const preview = await fetchPreview(url)
} catch (e) {
if (e.status === 500) return retryWithBackoff(() => fetchPreview(url))
throw e
} Defensive patterns
Strategy: retry
Validate before calling
const parsed = new URL(targetUrl)
if (!['http:', 'https:'].includes(parsed.protocol)) {
throw new Error('unsupported preview target')
} Type guard
function isHttpError(err: unknown): err is { code: number; message: string } {
return typeof err === 'object' && err !== null && typeof (err as any).code === 'number'
} Try / catch
try {
preview = await getLinkPreview(url)
} catch (err) {
if (isHttpError(err)) throw err // surface 4xx as-is
await backoffRetry(() => getLinkPreview(url), 3)
} Prevention
- Retry 500s with backoff — target-page fetch/parse failures are often transient
- Check server-side network access to the preview target, not just client access
- Read the Analytics-recorded underlying error before filing a bug
- Validate the URL on the client to reduce parse-path exceptions
When it happens
Trigger: Any thrown/uncaught error inside a link-preview route (e.g. parseLinkPreviewDetails throwing on fetch/parse failures) that is not an HttpError with a status code — network failures fetching the URL, HTML parsing exceptions, timeouts.
Common situations: Preview target URL unreachable or returns malformed HTML; upstream fetch timeouts; dependency bugs inside the preview parser; config problems surfacing as generic exceptions.
Understand the failure class
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/1d1d513ac3b65e4a.
Report an issue: GitHub.