{"id":"c1318dff867211e7","repo":"labstack/echo","slug":"errinvalidredirectcode","errorCode":"ErrInvalidRedirectCode","errorMessage":"invalid redirect status code","messagePattern":"invalid redirect status code","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"httperror.go","lineNumber":32,"sourceCode":"\tErrBadRequest                  = &httpError{http.StatusBadRequest}            // 400\n\tErrUnauthorized                = &httpError{http.StatusUnauthorized}          // 401\n\tErrForbidden                   = &httpError{http.StatusForbidden}             // 403\n\tErrNotFound                    = &httpError{http.StatusNotFound}              // 404\n\tErrMethodNotAllowed            = &httpError{http.StatusMethodNotAllowed}      // 405\n\tErrRequestTimeout              = &httpError{http.StatusRequestTimeout}        // 408\n\tErrStatusRequestEntityTooLarge = &httpError{http.StatusRequestEntityTooLarge} // 413\n\tErrUnsupportedMediaType        = &httpError{http.StatusUnsupportedMediaType}  // 415\n\tErrTooManyRequests             = &httpError{http.StatusTooManyRequests}       // 429\n\tErrInternalServerError         = &httpError{http.StatusInternalServerError}   // 500\n\tErrBadGateway                  = &httpError{http.StatusBadGateway}            // 502\n\tErrServiceUnavailable          = &httpError{http.StatusServiceUnavailable}    // 503\n)\n\n// The following errors fall into 500 (InternalServerError) category\nvar (\n\tErrValidatorNotRegistered = errors.New(\"validator not registered\")\n\tErrRendererNotRegistered  = errors.New(\"renderer not registered\")\n\tErrInvalidRedirectCode    = errors.New(\"invalid redirect status code\")\n\tErrCookieNotFound         = errors.New(\"cookie not found\")\n\tErrInvalidCertOrKeyType   = errors.New(\"invalid cert or key type, must be string or []byte\")\n\tErrInvalidListenerNetwork = errors.New(\"invalid listener network\")\n)\n\n// HTTPStatusCoder is an interface that errors can implement to produce status code for HTTP response\ntype HTTPStatusCoder interface {\n\tStatusCode() int\n}\n\n// StatusCode returns status code from err if it implements HTTPStatusCoder interface.\n// If err does not implement the interface, it returns 0.\nfunc StatusCode(err error) int {\n\tvar sc HTTPStatusCoder\n\tif errors.As(err, &sc) {\n\t\treturn sc.StatusCode()\n\t}\n\treturn 0","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/httperror.go#L14-L50","documentation":"ErrInvalidRedirectCode is returned by Context.Redirect when the status code is outside the HTTP 3xx redirect range (code < 300 || code > 308). Only 300-308 are valid redirect status codes per HTTP spec; passing anything else (200, 404, 201, etc.) is a programmer error.","triggerScenarios":"Calling c.Redirect(http.StatusCreated, url) or c.Redirect(200, url) or c.Redirect(404, url). Any status code outside [300,308] triggers it.","commonSituations":"Using http.StatusCreated (201) or http.StatusOK (200) by mistake instead of http.StatusMovedPermanently (301) or http.StatusFound (302). Copy-pasting a status constant from elsewhere.","solutions":["Use a valid redirect code: 301 (MovedPermanently), 302 (Found), 303 (SeeOther), 307 (TemporaryRedirect), or 308 (PermanentRedirect)","For non-redirect responses use c.String/c.JSON/c.HTML instead of c.Redirect","Define named constants for your redirect codes to avoid magic numbers"],"exampleFix":"// before\nc.Redirect(http.StatusCreated, \"/new\") // 201 — error\n\n// after\nc.Redirect(http.StatusFound, \"/new\") // 302 — ok","handlingStrategy":"validation","validationCode":"// Validate redirect code before calling Redirect\nfunc validRedirectCode(code int) bool {\n    return code >= 300 && code <= 308\n}\nif !validRedirectCode(code) {\n    return fmt.Errorf(\"invalid redirect code: %d\", code)\n}\nc.Redirect(code, url)","typeGuard":null,"tryCatchPattern":"if err := c.Redirect(code, url); err != nil {\n    if errors.Is(err, echo.ErrInvalidRedirectCode) {\n        return echo.NewHTTPError(http.StatusInternalServerError, \"misconfigured redirect\")\n    }\n    return err\n}","preventionTips":["Use named constants from net/http (StatusMovedPermanently, StatusFound, etc.) instead of magic numbers","Centralize redirect helper functions that enforce valid codes","Unit test redirect handlers with the expected 3xx codes"],"tags":["redirect","http-status","validation"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}