handle errors in client

This commit is contained in:
Rich Harris
2018-07-16 14:57:49 -04:00
parent af0bd1580d
commit 61e3b6c6a0
2 changed files with 23 additions and 7 deletions

View File

@@ -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: {} };