sundowndev/phoneinfoga · warning · Error
bad request
Error message
bad request
What it means
NewBadRequest wraps an error into a web Error carrying HTTP 400; when called with nil, it substitutes the literal error 'bad request'. Handlers call it for user-input failures (missing/invalid parameters) detected in validate and the *Scan handlers.
Source
Thrown at web/errors/errors.go:30
func (e *Error) Status() int {
return e.status
}
func (e *Error) Error() error {
return e.err
}
func (e *Error) String() string {
if e.err == nil {
return "unknown error"
}
return e.err.Error()
}
func NewBadRequest(err error) *Error {
if err == nil {
err = errors.New("bad request")
}
return &Error{
status: http.StatusBadRequest,
err: err,
}
}
func NewInternalError(err error) *Error {
if err == nil {
err = errors.New("internal error")
}
return &Error{
status: http.StatusInternalServerError,
err: err,
}
}
View on GitHub (pinned to 55807b05b7)
Solutions
- Always pass the underlying error: NewBadRequest(fmt.Errorf("missing number parameter: %w", err)) instead of nil
- Fix the client request to include a valid phone number query parameter in international format
- Check the HTTP response body/status: 400 means the request must be corrected, not retried as-is
Example fix
// before
return weberrors.NewBadRequest(nil) // client sees only "bad request"
// after
return weberrors.NewBadRequest(fmt.Errorf("query param 'number' is required")) Defensive patterns
Strategy: validation
Validate before calling
// client-side check before calling the web API
if !strings.HasPrefix(number, "+") || len(number) < 8 {
return errors.New("number parameter must be a full international phone number")
}
req, _ := http.NewRequest("GET", apiURL+"/scan?number="+url.QueryEscape(number), nil) Type guard
func isBadRequest(err *weberrors.Error) bool {
return err != nil && err.Status() == http.StatusBadRequest
} Try / catch
resp, err := client.Do(req)
if resp != nil && resp.StatusCode == http.StatusBadRequest {
var e struct{ Error string `json:"error"` }
_ = json.NewDecoder(resp.Body).Decode(&e)
return fmt.Errorf("fix request: %s", e.Error) // do not retry 400
} Prevention
- Always send ?number= in international format to the scan endpoints
- Treat every 400 as a request bug — never retry unchanged
- Server-side: pass a descriptive error to NewBadRequest instead of nil
- Validate inputs client-side before hitting the API
When it happens
Trigger: Calling NewBadRequest(nil) explicitly, or any web handler path where request validation fails — missing 'number' query parameter, invalid scan type in ValidateScanURL, malformed body — resulting in an HTTP 400 response.
Common situations: Client hitting the web API without the required ?number= parameter, sending an unsupported scanner type to ValidateScanURL, or a developer passing nil instead of a wrapped cause so the client only sees 'bad request'.
Related errors
AI-assisted analysis of sundowndev/phoneinfoga@55807b05b7 (2026-09-03).
Data as JSON: /api/errors/d3a33ceee734b97a.
Report an issue: GitHub.