Skip to content

Commit c8381ad

Browse files
committed
installer error fixes
1 parent 99119d8 commit c8381ad

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

connector/app/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def build_app(
5555

5656
@app.middleware("http")
5757
async def admin_auth_middleware(request, call_next):
58-
if request.url.path in ("/health",):
58+
path = request.url.path
59+
if path in ("/health",) or path.startswith("/setup"):
5960
return await call_next(request)
6061
if admin_token:
6162
provided = request.headers.get("X-Admin-Token") or request.query_params.get("admin_token")

connector/app/backend_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ def claim_setup_code(self, setup_code: str, name: str, version: str) -> tuple[st
3535
)
3636
if not r.ok:
3737
try:
38-
detail = r.json().get("error") or r.json().get("detail") or r.text
38+
payload = r.json()
39+
detail = payload.get("error") or payload.get("detail") or r.text
3940
except Exception: # noqa: BLE001
40-
detail = r.text
41+
detail = r.text or f"claim failed ({r.status_code})"
4142
raise RuntimeError(detail or f"claim failed ({r.status_code})")
4243
data = r.json()
4344
self.connector_id = data["connectorId"]

connector/app/wizard.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import uvicorn
1515
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
1616
from fastapi.responses import HTMLResponse, JSONResponse
17+
from pydantic import BaseModel
1718

1819
from .backend_client import BackendClient
1920
from .capture import validate_rtsp_stream
@@ -38,6 +39,11 @@ def parse_rtsp_urls(rtsp_text: str) -> list[str]:
3839
WIZARD_ROUTE_PREFIX = "/setup"
3940

4041

42+
class WizardClaimBody(BaseModel):
43+
setupCode: str = ""
44+
name: str = ""
45+
46+
4147
def wizard_page_html(route_prefix: str = "") -> str:
4248
"""HTML for the setup wizard; route_prefix is '' for standalone or '/setup' when mounted."""
4349
prefix = route_prefix.rstrip("/")
@@ -197,8 +203,13 @@ def wizard_page_html(route_prefix: str = "") -> str:
197203
headers: { 'Content-Type': 'application/json' },
198204
body: JSON.stringify({ setupCode: code, name })
199205
});
200-
const data = await r.json();
201-
if (!r.ok) throw new Error(data.detail || data.error || 'Claim failed');
206+
const text = await r.text();
207+
let data = {};
208+
try { data = text ? JSON.parse(text) : {}; } catch { data = { detail: text || r.statusText }; }
209+
if (!r.ok) {
210+
const err = data.detail || data.error || data.message || text || 'Claim failed';
211+
throw new Error(typeof err === 'string' ? err : JSON.stringify(err));
212+
}
202213
show(msg, true, 'Linked to store. Next: add cameras.');
203214
setTimeout(() => setStep(1), 500);
204215
} catch (e) { show(msg, false, e.message || String(e)); }
@@ -214,8 +225,13 @@ def wizard_page_html(route_prefix: str = "") -> str:
214225
fd.append('loop_file', document.getElementById('loopFile').checked ? 'true' : 'false');
215226
try {
216227
const r = await fetch('wizard/sources', { method: 'POST', body: fd });
217-
const data = await r.json();
218-
if (!r.ok) throw new Error(data.detail || data.error || 'Save failed');
228+
const text = await r.text();
229+
let data = {};
230+
try { data = text ? JSON.parse(text) : {}; } catch { data = { detail: text || r.statusText }; }
231+
if (!r.ok) {
232+
const err = data.detail || data.error || text || 'Save failed';
233+
throw new Error(typeof err === 'string' ? err : JSON.stringify(err));
234+
}
219235
document.getElementById('doneText').textContent =
220236
`Monitoring ${data.cameraCount} source(s). Clips upload on motion.`;
221237
setStep(2);
@@ -268,18 +284,18 @@ def wizard_status():
268284
}
269285

270286
@app.post(f"{api_prefix}/claim")
271-
def wizard_claim(body: dict):
272-
code = (body.get("setupCode") or body.get("setup_code") or "").strip()
273-
name = (body.get("name") or cfg.connector_name or "edge-connector-1").strip()
287+
def wizard_claim(body: WizardClaimBody):
288+
code = (body.setupCode or "").strip().upper()
289+
name = (body.name or cfg.connector_name or "edge-connector-1").strip()
274290
if not code:
275-
raise HTTPException(400, "setupCode is required")
291+
raise HTTPException(status_code=400, detail="setupCode is required")
276292
try:
277293
w = load_wizard_config() or WizardConfig()
278294
w.setup_code = code
279295
w.connector_name = name
280296
cid, store_id = claim_setup(client, store, w, cfg.version)
281297
except Exception as exc: # noqa: BLE001
282-
raise HTTPException(400, str(exc)) from exc
298+
raise HTTPException(status_code=400, detail=str(exc)) from exc
283299
state.connector_id = cid
284300
state.log(f"Wizard: claimed setup code → connector {cid} store {store_id}")
285301
w = load_wizard_config() or WizardConfig()

0 commit comments

Comments
 (0)