Skip to content

Commit 30c355a

Browse files
committed
Update update_dns_record.ts
1 parent 6ebd2d5 commit 30c355a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/api/update_dns_record.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1+
import ApiRequestError from '../error/api_request_error.ts';
2+
import FetchRequestError from '../error/fetch_request_error.ts';
13
import { DnsRecord } from '../record/dns_record.ts';
24
import { ApiRequestOptions } from './api_request_options.ts';
35

46
export default function updateDnsRecord(
57
record : DnsRecord,
68
options : ApiRequestOptions
79
) : void {
8-
10+
fetch(
11+
`${options.apiEndpoint}zones/${options.zoneId}/dns_records/${options.recordId}`,
12+
{
13+
method: 'PATCH',
14+
headers: {
15+
'Content-Type': 'application/json',
16+
'Authorization': `Bearer ${options.token}`
17+
},
18+
body: JSON.stringify(record)
19+
}
20+
)
21+
.then((response) => {
22+
if (response.ok) {
23+
return response.json();
24+
}
25+
throw new FetchRequestError({cause: response.statusText});
26+
})
27+
.then((responseJson) => {
28+
if (!responseJson.success) {
29+
throw new ApiRequestError({cause: responseJson.errors})
30+
}
31+
});
932
}

0 commit comments

Comments
 (0)