package web

import (
    "runtime"

    "github.com/valyala/fasthttp"
    "go.uber.org/zap"

    "tiup-log-collector/log"
)


func recoverError(msg string, ctx *fasthttp.RequestCtx) {
    if err := recover(); err != nil {
        buf := make([]byte, 4096)
        rawStack := string(buf[:runtime.Stack(buf, false)])
        log.L().Error(msg, zap.Any("raw", err), zap.String("stack", rawStack))

        renderMsg(ctx, fasthttp.StatusInternalServerError, "We encountered an internal error")
    }
}
