feat: add type to AbortError (#45)

This commit is contained in:
dirkmc 2019-04-18 18:44:17 +08:00 committed by Jacob Heun
parent b30ee5f6af
commit 4fd37bb616
2 changed files with 7 additions and 0 deletions

View File

@ -62,6 +62,7 @@ module.exports = (common) => {
await socket await socket
} catch (err) { } catch (err) {
expect(err.code).to.eql(AbortError.code) expect(err.code).to.eql(AbortError.code)
expect(err.type).to.eql(AbortError.type)
return return
} }
expect.fail('Did not throw error with code ' + AbortError.code) expect.fail('Did not throw error with code ' + AbortError.code)
@ -80,6 +81,7 @@ module.exports = (common) => {
await socket await socket
} catch (err) { } catch (err) {
expect(err.code).to.eql(AbortError.code) expect(err.code).to.eql(AbortError.code)
expect(err.type).to.eql(AbortError.type)
return return
} finally { } finally {
connector.restore() connector.restore()

View File

@ -4,11 +4,16 @@ class AbortError extends Error {
constructor () { constructor () {
super('AbortError') super('AbortError')
this.code = AbortError.code this.code = AbortError.code
this.type = AbortError.type
} }
static get code () { static get code () {
return 'ABORT_ERR' return 'ABORT_ERR'
} }
static get type () {
return 'aborted'
}
} }
module.exports = { module.exports = {