AlexxIT/go2rtc · error

res.Status

Error message

res.Status

What it means

Dial in the ISAPI client returns a plain error built from the HTTP response status line whenever the camera/device responds with a status code other than 200 OK. It is the library's way of surfacing any non-OK HTTP response (auth failure, 404, 500, etc.) from the device during connection setup. Because it embeds only res.Status, the text is the raw status line, e.g. '401 Unauthorized'.

Solutions

  1. Check the status text in the error message and fix the corresponding cause (401/403 => credentials/permissions, 404 => wrong path, 5xx => device-side issue).
  2. Verify the ISAPI URL, port and path configured for the client are correct for the device model.
  3. Confirm username/password and that the account has permission to access ISAPI endpoints.
  4. Inspect the device's web interface / ISAPI documentation for the endpoint and retry.

Example fix

// before
cli := isapi.NewClient(isapi.WithURL("http://cam:80/ISAPI/Streaming/...").WithAuth("admin", "wrongpass"))
conn, err := cli.Dial()
// after
// use correct credentials and endpoint; handle the error by inspecting the status
conn, err := cli.Dial()
if err != nil {
	if strings.Contains(err.Error(), "401") { /* fix credentials */ }
	return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: nothing to check beforehand, but verify endpoint reachability
resp, err := http.Get(cameraURL)
if err == nil && resp.StatusCode != http.StatusOK {
	return fmt.Errorf("camera returned %s", resp.Status)
}

Try / catch

conn, err := cli.Dial()
if err != nil {
	if strings.Contains(err.Error(), "401") || strings.Contains(err.Error(), "403") {
		// re-check credentials then retry once
	}
	return fmt.Errorf("isapi dial failed: %w", err)
}

Prevention

When it happens

Trigger: Calling pkg/isapi client Dial when the HTTP response from the ISAPI endpoint has StatusCode != http.StatusOK — e.g. wrong credentials (401), wrong URL path (404), or device rejecting the request (500).

Common situations: Incorrect camera username/password in config; pointing at a non-ISAPI port or path; device firmware returning 403/404 for a given API; proxy or load balancer answering instead of the camera.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/430eb2b936655a74. Report an issue: GitHub.

Appendix: source

Thrown at pkg/isapi/client.go:58

	}
	return client, err
}

func (c *Client) Dial() (err error) {
	link := c.url + "/ISAPI/System/TwoWayAudio/channels"
	req, err := http.NewRequest("GET", link, nil)
	if err != nil {
		return err
	}

	res, err := tcp.Do(req)
	if err != nil {
		return
	}

	if res.StatusCode != http.StatusOK {
		tcp.Close(res)
		return errors.New(res.Status)
	}

	b, err := io.ReadAll(res.Body)
	if err != nil {
		return err
	}

	xml := string(b)

	codec := core.Between(xml, `<audioCompressionType>`, `<`)
	switch codec {
	case "G.711ulaw":
		codec = core.CodecPCMU
	case "G.711alaw":
		codec = core.CodecPCMA
	default:
		return nil
	}

View on GitHub (pinned to c245815e75)