P0 fixes: - ModelError.Is(): use exact matching instead of substring contains() - shouldClearStickySession: add context param for cancellation/tracing P1 fixes: - TODO stubs: return 501 Not Implemented errors - validateInstanceSignature: deduplicate to shared validateCodeSignature() - Error messages: standardize to English only - http.go: remove pseudo if-else with duplicate branches
26 lines
629 B
Go
26 lines
629 B
Go
// Package googleapi provides helpers for Google-style API responses.
|
|
package googleapi
|
|
|
|
import "net/http"
|
|
|
|
// HTTPStatusToGoogleStatus maps HTTP status codes to Google-style error status strings.
|
|
func HTTPStatusToGoogleStatus(status int) string {
|
|
switch status {
|
|
case http.StatusBadRequest:
|
|
return "INVALID_ARGUMENT"
|
|
case http.StatusUnauthorized:
|
|
return "UNAUTHENTICATED"
|
|
case http.StatusForbidden:
|
|
return "PERMISSION_DENIED"
|
|
case http.StatusNotFound:
|
|
return "NOT_FOUND"
|
|
case http.StatusTooManyRequests:
|
|
return "RESOURCE_EXHAUSTED"
|
|
default:
|
|
if status >= 500 {
|
|
return "INTERNAL"
|
|
}
|
|
return "UNKNOWN"
|
|
}
|
|
}
|