()
| 14031 | |
| 14032 | async function postPwnAPI(endpoint, payload = {}) { |
| 14033 | const response = await fetch(endpoint, { |
| 14034 | method: 'POST', |
| 14035 | headers: { |
| 14036 | 'Content-Type': 'application/json' |
| 14037 | }, |
| 14038 | body: JSON.stringify(payload) |
| 14039 | }); |
| 14040 | |
| 14041 | let data = null; |
| 14042 | try { |
| 14043 | data = await response.json(); |
| 14044 | } catch (error) { |
| 14045 | data = null; |
| 14046 | } |
| 14047 | |
| 14048 | if (!response.ok || (data && data.success === false)) { |
| 14049 | const errorMessage = data && (data.error || data.message) |
| 14050 | ? (data.error || data.message) |
| 14051 | : `Request failed (${response.status})`; |
| 14052 | throw new Error(errorMessage); |
no test coverage detected