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