add catch ajax error

This commit is contained in:
qingwei.li 2016-11-28 12:17:57 +08:00
commit ec58149aad
2 changed files with 5 additions and 2 deletions

View file

@ -5,6 +5,7 @@ export default function (url, options = {}) {
xhr.send()
return {
then: cb => xhr.addEventListener('load', cb)
then: cb => xhr.addEventListener('load', cb),
catch: cb => xhr.addEventListener('error', cb)
}
}

View file

@ -40,7 +40,8 @@ class Docsify {
}
load () {
ajax(`${this.loc}.md`).then(res => {
ajax(`${this.loc}.md`)
.then(res => {
const target = res.target
if (target.status >= 400) {
this.render('not found')
@ -52,6 +53,7 @@ class Docsify {
}
}
})
.catch(_ => this.render('not found'))
}
render (content) {