Merged PR 65: BUG533:アプリインポート時エラー発生時のメッセージ表示
BUG533:アプリインポート時エラー発生時のメッセージ表示 原因:フィールド作成時エラーが発生するとき、Backend側exceptionがThrowされない 対策:フィールド作成時エラーが発生するとき、例外をThrowして、frontend側を正しい表示するように対応しました Related work items: #533
This commit is contained in:
@@ -194,8 +194,9 @@ 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):
|
||||||
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
||||||
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
||||||
|
|||||||
@@ -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):
|
self.detail = str(e)
|
||||||
if(str(e) == ''):
|
self.status_code = 500
|
||||||
content += e.detail
|
if isinstance(e,httpx.HTTPStatusError):
|
||||||
self.detail = e.detail
|
try:
|
||||||
self.status_code = e.status_code
|
error_response = e.response.json()
|
||||||
else:
|
self.detail = error_response.get('message', self.detail)
|
||||||
self.detail = str(e)
|
self.status_code = e.response.status_code
|
||||||
content += str(e)
|
content += self.detail
|
||||||
self.status_code = 500
|
except ValueError:
|
||||||
if(len(content) > 5000):
|
pass
|
||||||
content =content[0:5000]
|
elif hasattr(e, 'detail'):
|
||||||
self.error = ErrorCreate(location=location,title=title,content=content)
|
self.detail = e.detail
|
||||||
|
self.status_code = e.status_code if hasattr(e, 'status_code') else 500
|
||||||
|
content += e.detail
|
||||||
|
else:
|
||||||
|
self.detail = str(e)
|
||||||
|
self.status_code = 500
|
||||||
|
content += str(e)
|
||||||
|
|
||||||
|
if len(content) > 5000:
|
||||||
|
content = content[:5000]
|
||||||
|
|
||||||
|
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()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { createUploaderComponent, useQuasar } from 'quasar';
|
import { createUploaderComponent, useQuasar } from 'quasar';
|
||||||
import { useAuthStore } from 'src/stores/useAuthStore';
|
import { useAuthStore } from 'src/stores/useAuthStore';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
const $q=useQuasar();
|
const $q=useQuasar();
|
||||||
@@ -40,7 +40,7 @@ import { ref } from 'vue';
|
|||||||
function onUploadFinished({xhr}:{xhr:XMLHttpRequest}){
|
function onUploadFinished({xhr}:{xhr:XMLHttpRequest}){
|
||||||
let msg="ファイルのアップロードが完了しました。";
|
let msg="ファイルのアップロードが完了しました。";
|
||||||
if(xhr && xhr.response){
|
if(xhr && xhr.response){
|
||||||
msg=`${msg} (${xhr.responseText})`;
|
msg=`${msg} (${xhr.responseText})`;
|
||||||
}
|
}
|
||||||
$q.notify({
|
$q.notify({
|
||||||
type: 'positive',
|
type: 'positive',
|
||||||
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user