未验证 提交 8e562d4e 编写于 作者: P Peter Pan 提交者: GitHub

minor bugs fix (#804)

* fix: error message cannot display correctly

* fix: query string missing when redirect from root to index
上级 1802fd96
......@@ -80,9 +80,13 @@ export async function fetcher<T = unknown>(url: string, options?: RequestInit):
}
let response: Data<T> | T;
try {
if (res.headers.get('content-type')?.includes('application/json')) {
try {
response = await res.json();
} catch (e) {
const t = await logErrorAndReturnT(e);
throw new Error(t('errors:parse-error'));
}
if (response && 'status' in response) {
if (response.status !== 0) {
const t = await logErrorAndReturnT(response);
......@@ -93,7 +97,13 @@ export async function fetcher<T = unknown>(url: string, options?: RequestInit):
}
return response;
} else {
const data = await res.blob();
let data: Blob;
try {
data = await res.blob();
} catch (e) {
const t = await logErrorAndReturnT(e);
throw new Error(t('errors:parse-error'));
}
const disposition = res.headers.get('Content-Disposition');
// support safari
if (!data.arrayBuffer) {
......@@ -115,10 +125,6 @@ export async function fetcher<T = unknown>(url: string, options?: RequestInit):
}
return {data, type: res.headers.get('Content-Type'), filename};
}
} catch (e) {
const t = await logErrorAndReturnT(e);
throw new Error(t('errors:parse-error'));
}
}
export const cycleFetcher = async <T = unknown>(urls: string[], options?: RequestInit): Promise<T[]> => {
......
......@@ -69,6 +69,12 @@ def create_app(args):
public_path = args.public_path
api_path = public_path + '/api'
def append_query_string(url):
query_string = ''
if request.query_string:
query_string = '?' + request.query_string.decode()
return url + query_string
@babel.localeselector
def get_locale():
lang = args.language
......@@ -87,7 +93,7 @@ def create_app(args):
@app.route('/')
def base():
return redirect(public_path, code=302)
return redirect(append_query_string(public_path), code=302)
@app.route('/favicon.ico')
def favicon():
......@@ -98,10 +104,7 @@ def create_app(args):
@app.route(public_path + '/')
def index():
query_string = ''
if request.query_string:
query_string = '?' + request.query_string.decode()
return redirect(public_path + '/index' + query_string, code=302)
return redirect(append_query_string(public_path + '/index'), code=302)
@app.route(public_path + '/<path:filename>')
def serve_static(filename):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册