mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 08:25:26 +08:00
29 lines
631 B
Go
29 lines
631 B
Go
package gemini
|
|
|
|
import "net/http"
|
|
|
|
func writeGeminiError(w http.ResponseWriter, status int, message string) {
|
|
errorStatus := "INVALID_ARGUMENT"
|
|
switch status {
|
|
case http.StatusUnauthorized:
|
|
errorStatus = "UNAUTHENTICATED"
|
|
case http.StatusForbidden:
|
|
errorStatus = "PERMISSION_DENIED"
|
|
case http.StatusTooManyRequests:
|
|
errorStatus = "RESOURCE_EXHAUSTED"
|
|
case http.StatusNotFound:
|
|
errorStatus = "NOT_FOUND"
|
|
default:
|
|
if status >= 500 {
|
|
errorStatus = "INTERNAL"
|
|
}
|
|
}
|
|
writeJSON(w, status, map[string]any{
|
|
"error": map[string]any{
|
|
"code": status,
|
|
"message": message,
|
|
"status": errorStatus,
|
|
},
|
|
})
|
|
}
|