Merge pull request 'development' (#122) from development into main
Reviewed-on: #122
This commit was merged in pull request #122.
This commit is contained in:
@@ -4,6 +4,7 @@ NetBox API client for interacting with NetBox REST API.
|
|||||||
Provides a generic HTTP client with methods for all standard REST operations.
|
Provides a generic HTTP client with methods for all standard REST operations.
|
||||||
Individual tool modules use this client for their specific endpoints.
|
Individual tool modules use this client for their specific endpoints.
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
from typing import List, Dict, Optional, Any, Union
|
from typing import List, Dict, Optional, Any, Union
|
||||||
@@ -83,7 +84,20 @@ class NetBoxClient:
|
|||||||
if response.status_code == 204 or not response.content:
|
if response.status_code == 204 or not response.content:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return response.json()
|
# Parse JSON with diagnostic error handling
|
||||||
|
try:
|
||||||
|
return response.json()
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error(
|
||||||
|
f"JSON decode failed. Status: {response.status_code}, "
|
||||||
|
f"Content-Length: {len(response.content)}, "
|
||||||
|
f"Content preview: {response.content[:200]!r}"
|
||||||
|
)
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid JSON response from NetBox: {e}. "
|
||||||
|
f"Status code: {response.status_code}, "
|
||||||
|
f"Content length: {len(response.content)} bytes"
|
||||||
|
) from e
|
||||||
|
|
||||||
def list(
|
def list(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user