generated from VLADIMIR/template
up
This commit is contained in:
@@ -354,28 +354,32 @@ func customErrorHandler(
|
||||
) {
|
||||
var maxBytesErr *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesErr) {
|
||||
writeTooLargeError(w, marshaler)
|
||||
writeTooLargeError(w, marshaler, r.URL.Path)
|
||||
return
|
||||
}
|
||||
if status.Code(err) == codes.ResourceExhausted {
|
||||
switch r.URL.Path {
|
||||
case "/api/files/upload", "/api/scenarios/archive":
|
||||
writeTooLargeError(w, marshaler)
|
||||
writeTooLargeError(w, marshaler, r.URL.Path)
|
||||
return
|
||||
}
|
||||
}
|
||||
if status.Code(err) == codes.InvalidArgument &&
|
||||
strings.Contains(status.Convert(err).Message(), "request body too large") {
|
||||
writeTooLargeError(w, marshaler)
|
||||
writeTooLargeError(w, marshaler, r.URL.Path)
|
||||
return
|
||||
}
|
||||
runtime.DefaultHTTPErrorHandler(ctx, mux, marshaler, w, r, err)
|
||||
}
|
||||
|
||||
func writeTooLargeError(w http.ResponseWriter, marshaler runtime.Marshaler) {
|
||||
func writeTooLargeError(w http.ResponseWriter, marshaler runtime.Marshaler, route string) {
|
||||
limit := maxFileSize
|
||||
if route == "/api/scenarios/archive" {
|
||||
limit = scenario_archive.MaxArchiveSize()
|
||||
}
|
||||
w.Header().Set("Content-Type", marshaler.ContentType(nil))
|
||||
w.WriteHeader(http.StatusRequestEntityTooLarge)
|
||||
_ = marshaler.NewEncoder(w).Encode(map[string]string{
|
||||
"error": fmt.Sprintf("файл слишком большой (лимит %d МБ)", maxFileSize>>20),
|
||||
"error": fmt.Sprintf("файл слишком большой (лимит %d МБ)", limit>>20),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user