(envelope: Envelope<T>)
| 36 | * `null` — callers asking for a non-nullable type should narrow). |
| 37 | */ |
| 38 | export function unwrap<T>(envelope: Envelope<T>): T { |
| 39 | if (envelope.code !== 0) throw new EnvelopeError(envelope); |
| 40 | if (envelope.data === null) { |
| 41 | // `code: 0 + data: null` is reserved for "no body" success envelopes; the |
| 42 | // current server surface always returns a non-null data on success, so |
| 43 | // surface this as a hard error rather than silently returning `null`. |
| 44 | throw new EnvelopeError({ ...envelope, code: 50001, msg: 'success envelope had null data' }); |
| 45 | } |
| 46 | return envelope.data; |
| 47 | } |
no outgoing calls
no test coverage detected