Go

Go

Made by DeepSource

Suspicious http.Error call without following return GO-W4008

Bug risk
Major

Not returning after calling http.Error in a handler may execute code paths that should not be executed in case of an error. It is recommended to return after calling http.Error.

Bad practice

package main

import (
    "net/http"
)

func FooHandler(w http.ResponseWriter, r *http.Request) {
    err := ...
    if err != nil {
        http.Error(w, err, 500)
    }
}

Recommended

package main

import (
    "net/http"
)

func FooHandler(w http.ResponseWriter, r *http.Request) {
    err := ...
    if err != nil {
        http.Error(w, err, 500)
        return
    }
}