* Asserts that the handler object is a request handler. * * @param {object} handler * @param {string} method * @param {string} [upgrade] * @returns {asserts handler is import('../api/api-request').RequestHandler}
(handler, method, upgrade)
| 560 | * @returns {asserts handler is import('../api/api-request').RequestHandler} |
| 561 | */ |
| 562 | function assertRequestHandler (handler, method, upgrade) { |
| 563 | if (!handler || typeof handler !== 'object') { |
| 564 | throw new InvalidArgumentError('handler must be an object') |
| 565 | } |
| 566 | |
| 567 | if (typeof handler.onRequestStart !== 'function') { |
| 568 | throw new InvalidArgumentError('invalid onRequestStart method') |
| 569 | } |
| 570 | |
| 571 | if (typeof handler.onResponseError !== 'function') { |
| 572 | throw new InvalidArgumentError('invalid onResponseError method') |
| 573 | } |
| 574 | |
| 575 | if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) { |
| 576 | throw new InvalidArgumentError('invalid onBodySent method') |
| 577 | } |
| 578 | |
| 579 | if (typeof handler.onRequestSent !== 'function' && handler.onRequestSent !== undefined) { |
| 580 | throw new InvalidArgumentError('invalid onRequestSent method') |
| 581 | } |
| 582 | |
| 583 | if (upgrade || method === 'CONNECT') { |
| 584 | if (typeof handler.onRequestUpgrade !== 'function') { |
| 585 | throw new InvalidArgumentError('invalid onRequestUpgrade method') |
| 586 | } |
| 587 | } else { |
| 588 | if (typeof handler.onResponseStart !== 'function') { |
| 589 | throw new InvalidArgumentError('invalid onResponseStart method') |
| 590 | } |
| 591 | |
| 592 | if (typeof handler.onResponseData !== 'function') { |
| 593 | throw new InvalidArgumentError('invalid onResponseData method') |
| 594 | } |
| 595 | |
| 596 | if (typeof handler.onResponseEnd !== 'function') { |
| 597 | throw new InvalidArgumentError('invalid onResponseEnd method') |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * A body is disturbed if it has been read from and it cannot be re-used without |
no outgoing calls
no test coverage detected
searching dependent graphs…