mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-14 12:04:39 +00:00
handle errors in client
This commit is contained in:
@@ -123,10 +123,6 @@ function prepare_page(target: Target): Promise<{
|
||||
error = { statusCode: 500, message: err };
|
||||
return [];
|
||||
}).then(results => {
|
||||
if (error) {
|
||||
console.error('TODO', error);
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
return { redirect };
|
||||
}
|
||||
@@ -134,6 +130,25 @@ function prepare_page(target: Target): Promise<{
|
||||
const get_params = page.parts[page.parts.length - 1].params || (() => ({}));
|
||||
const params = get_params(target.match);
|
||||
|
||||
if (error) {
|
||||
const props = {
|
||||
path,
|
||||
query,
|
||||
params,
|
||||
error: typeof error.message === 'string' ? new Error(error.message) : error.message,
|
||||
status: error.statusCode
|
||||
};
|
||||
|
||||
return {
|
||||
data: Object.assign({}, props, {
|
||||
child: {
|
||||
component: routes.error,
|
||||
props
|
||||
}
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// TODO skip unchanged segments
|
||||
const props = { path, query };
|
||||
const data = { path, query, params, child: {} };
|
||||
|
||||
Reference in New Issue
Block a user