mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 05:40:17 +00:00
Return HTTP Exception on /api/update API call failure
- Previously the backend was just throwing backend error. The frontend calling the /update API wasn't getting notified - Now the frontend can react appropriately and make the issue visible to the user
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
# Standard Packages
|
# Standard Packages
|
||||||
import yaml
|
import yaml
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from fastapi import HTTPException
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from src.configure import configure_processor, configure_search
|
from src.configure import configure_processor, configure_search
|
||||||
@@ -114,12 +114,22 @@ def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Opti
|
|||||||
|
|
||||||
@api.get('/update')
|
@api.get('/update')
|
||||||
def update(t: Optional[SearchType] = None, force: Optional[bool] = False):
|
def update(t: Optional[SearchType] = None, force: Optional[bool] = False):
|
||||||
|
try:
|
||||||
state.search_index_lock.acquire()
|
state.search_index_lock.acquire()
|
||||||
state.model = configure_search(state.model, state.config, regenerate=force, t=t)
|
state.model = configure_search(state.model, state.config, regenerate=force, t=t)
|
||||||
state.search_index_lock.release()
|
state.search_index_lock.release()
|
||||||
|
except ValueError as e:
|
||||||
|
logger.error(e)
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
else:
|
||||||
logger.info("Search Index updated via API call")
|
logger.info("Search Index updated via API call")
|
||||||
|
|
||||||
|
try:
|
||||||
state.processor_config = configure_processor(state.config.processor)
|
state.processor_config = configure_processor(state.config.processor)
|
||||||
|
except ValueError as e:
|
||||||
|
logger.error(e)
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
else:
|
||||||
logger.info("Processor reconfigured via API call")
|
logger.info("Processor reconfigured via API call")
|
||||||
|
|
||||||
return {'status': 'ok', 'message': 'khoj reloaded'}
|
return {'status': 'ok', 'message': 'khoj reloaded'}
|
||||||
|
|||||||
Reference in New Issue
Block a user