* Throws a ``SERVER_ERROR`` if this response is not ok.
()
| 818 | * Throws a ``SERVER_ERROR`` if this response is not ok. |
| 819 | */ |
| 820 | assertOk() { |
| 821 | if (this.ok()) { |
| 822 | return; |
| 823 | } |
| 824 | let { message, error } = this.#error; |
| 825 | if (message === "") { |
| 826 | message = `server response ${this.statusCode} ${this.statusMessage}`; |
| 827 | } |
| 828 | let requestUrl = null; |
| 829 | if (this.request) { |
| 830 | requestUrl = this.request.url; |
| 831 | } |
| 832 | let responseBody = null; |
| 833 | try { |
| 834 | if (this.#body) { |
| 835 | responseBody = (0, utf8_js_1.toUtf8String)(this.#body); |
| 836 | } |
| 837 | } |
| 838 | catch (e) { } |
| 839 | (0, errors_js_1.assert)(false, message, "SERVER_ERROR", { |
| 840 | request: (this.request || "unknown request"), response: this, error, |
| 841 | info: { |
| 842 | requestUrl, responseBody, |
| 843 | responseStatus: `${this.statusCode} ${this.statusMessage}` |
| 844 | } |
| 845 | }); |
| 846 | } |
| 847 | } |
| 848 | exports.FetchResponse = FetchResponse; |
| 849 | function getTime() { return (new Date()).getTime(); } |
no test coverage detected