BUG533:アプリインポート時エラー発生時のメッセージ表示

This commit is contained in:
xiaozhe.ma
2024-07-26 09:56:12 +09:00
parent 96722d9c2f
commit 6023237db9
3 changed files with 46 additions and 18 deletions

View File

@@ -194,6 +194,7 @@ def addfieldstokintone(app:str,fields:dict,c:config.KINTONE_ENV,revision:str = N
else: else:
data = {"app":app,"properties":fields} data = {"app":app,"properties":fields}
r = httpx.post(url,headers=headers,data=json.dumps(data)) r = httpx.post(url,headers=headers,data=json.dumps(data))
r.raise_for_status()
return r.json() return r.json()
def updatefieldstokintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV): def updatefieldstokintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV):

View File

@@ -1,22 +1,35 @@
from fastapi import HTTPException, status from fastapi import HTTPException, status
import httpx
from app.db.schemas import ErrorCreate from app.db.schemas import ErrorCreate
from app.db.session import SessionLocal from app.db.session import SessionLocal
from app.db.crud import create_log from app.db.crud import create_log
class APIException(Exception): class APIException(Exception):
def __init__(self, location: str, title: str, content: str, e: Exception): def __init__(self, location: str, title: str, content: str, e: Exception):
if(str(e) == ''): self.detail = str(e)
content += e.detail self.status_code = 500
if isinstance(e,httpx.HTTPStatusError):
try:
error_response = e.response.json()
self.detail = error_response.get('message', self.detail)
self.status_code = e.response.status_code
content += self.detail
except ValueError:
pass
elif hasattr(e, 'detail'):
self.detail = e.detail self.detail = e.detail
self.status_code = e.status_code self.status_code = e.status_code if hasattr(e, 'status_code') else 500
content += e.detail
else: else:
self.detail = str(e) self.detail = str(e)
content += str(e)
self.status_code = 500 self.status_code = 500
if(len(content) > 5000): content += str(e)
content =content[0:5000]
if len(content) > 5000:
content = content[:5000]
self.error = ErrorCreate(location=location, title=title, content=content) self.error = ErrorCreate(location=location, title=title, content=content)
super().__init__(self.error)
def writedblog(exc: APIException): def writedblog(exc: APIException):
db = SessionLocal() db = SessionLocal()

View File

@@ -52,14 +52,28 @@ import { ref } from 'vue';
}, 2000); }, 2000);
} }
/**
* 例外発生時、responseからエラー情報を取得する
* @param xhr
*/
function getResponseError(xhr:XMLHttpRequest){
try{
const resp = JSON.parse(xhr.responseText);
return 'detail' in resp ? resp.detail:'';
}catch(err){
return xhr.responseText;
}
}
/** /**
* *
* @param info ファイルアップロード失敗時の処理 * @param info ファイルアップロード失敗時の処理
*/ */
function onFailed({files,xhr}:{files: readonly any[],xhr:any}){ function onFailed({files,xhr}:{files: readonly any[],xhr:XMLHttpRequest}){
let msg ="ファイルアップロードが失敗しました。"; let msg ="ファイルアップロードが失敗しました。";
if(xhr && xhr.status){ if(xhr && xhr.status){
msg=`${msg} (${xhr.status }:${xhr.statusText})` const detail = getResponseError(xhr);
msg=`${msg} (${xhr.status }:${detail})`
} }
$q.notify({ $q.notify({
type:"negative", type:"negative",