Senior
What is a 404 and what other 4xx codes do you know?
sobes.tech AI
Answer from AI
Code 404 is an HTTP status indicating "Not Found." It is returned when the client requests a resource that does not exist on the server.
Other common 4xx codes:
- 400 Bad Request — incorrect request, such as a syntax error.
- 401 Unauthorized — authentication is required.
- 403 Forbidden — access is denied, even if the user is authenticated.
- 405 Method Not Allowed — the HTTP method is not allowed for this resource.
- 408 Request Timeout — the request timeout has expired.
- 429 Too Many Requests — the request limit has been exceeded.
In Go, when working with HTTP, you can use constants from the net/http package, for example:
import (
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Page not found", http.StatusNotFound) // 404
}