UNPKG

1.68 kBtext/coffeescriptView Raw
1error = require 'tea-error'
2
3AxiomError = error 'AxiomError'
4
5class NoRespondersError extends AxiomError
6 name: 'AxiomError/NoRespondersError'
7
8 constructor: (context, start) ->
9 {channel} = context
10 message = "No responders for request: '#{channel}'"
11
12 super message, context, start
13
14class AmbiguousRespondersError extends AxiomError
15 name: 'AxiomError/AmbiguousResondersError'
16
17 constructor: (context, start) ->
18 {channel, responders} = context
19 message = "Ambiguous: #{responders.length} responders for request: '#{channel}'"
20
21 super message, context, start
22
23class RequestTimeoutError extends AxiomError
24 name: 'AxiomError/RequestTimeoutError'
25
26 constructor: (context, start) ->
27 {channel, ms} = context
28 time = if ms? then "after #{ms}ms " else ''
29 message = "Request timed out #{time}on channel: '#{channel}'"
30
31 super message, context, start
32
33class DelegateTimeoutError extends AxiomError
34 name: 'AxiomError/RequestTimeoutError'
35
36 constructor: (context, start) ->
37 {channel, responderId, ms} = context
38 time = if ms? then "after #{ms}ms " else ''
39 message = "Responder with id '#{responderId}' timed out #{time}on channel: '#{channel}'"
40
41 super message, context, start
42
43
44class ErrorCollection extends AxiomError
45 name: 'AxiomError/ErrorCollection'
46
47 constructor: (context, start) ->
48 {channel, errors} = context
49
50 errArray = for responder, error of errors
51 error.stack
52 message = "Received errors from channel '#{channel}':\n#{errArray.join '\n'}"
53
54 super message, context, start
55
56module.exports = {NoRespondersError, AmbiguousRespondersError,
57 RequestTimeoutError, DelegateTimeoutError, ErrorCollection}