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