1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-03-12 21:48:39 +01:00

improved error handling

This commit is contained in:
Enrico Fasoli 2015-11-20 20:32:12 +01:00
parent 640b14a519
commit 78e78e74fe

View File

@ -100,9 +100,9 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
} else { } else {
var url = r.Path var url = r.Path
if(url === undefined){ if(url === undefined){
console.log('UNDEFINED URL',r) console.log('Could not resolve',n)
} this.ee.emit('error',r.Message)
if(this.users[n] != url) this.isUserProfile(url,(isit,err) => { } else if(this.users[n] != url) this.isUserProfile(url,(isit,err) => {
if(isit){ if(isit){
console.log(n,'is a user') console.log(n,'is a user')
if(this.users[n] === undefined) this.ee.emit('user',n,url) if(this.users[n] === undefined) this.ee.emit('user',n,url)
@ -127,12 +127,17 @@ BoardsAPI.prototype.isUserProfile = function(addr,done){
this.ipfs.cat(addr+this.baseurl+'ipfs-boards-version.txt',(err,r) => { this.ipfs.cat(addr+this.baseurl+'ipfs-boards-version.txt',(err,r) => {
if(err) return done(false,err) if(err) return done(false,err)
replyAsObj(r,false,(_,res) => { replyAsObj(r,false,(_,res) => {
var v = res.trim() if(!res || !res.trim){
console.log('Version in profile snapshot',addr,'is',v) console.log('Could not read version from',addr)
if(v === this.version) } else {
done(true) var v = res.trim()
else console.log('Version in profile snapshot',addr,'is',v)
done(false,'version mismatch: is "'+v+'" but should be "'+this.version+'"') if(v === this.version){
done(true)
} else {
done(false,'version mismatch: is "'+v+'" but should be "'+this.version+'"')
}
}
}) })
}) })
} }