Skip to content

Commit

Permalink
Update create_dns_record.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx committed Aug 30, 2024
1 parent 46dd2ac commit 9dd1728
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/api/create_dns_record.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import ApiRequestError from '../error/api_request_error.ts';
import FetchRequestError from '../error/fetch_request_error.ts';
import { DnsRecord } from '../record/dns_record.ts';
import { ApiRequestOptions } from './api_request_options.ts';

export default function createDnsRecord(
record : DnsRecord,
options : ApiRequestOptions
) : void {

fetch(
`${options.apiEndpoint}zones/${options.zoneId}/dns_records`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${options.token}`
},
body: JSON.stringify(record)
}
)
.then((response) => {
if (!response.ok) {
return response.json();
}
throw new FetchRequestError({cause: response.statusText});
})
.then((responseJson) => {
if (!responseJson.success) {
throw new ApiRequestError({cause: responseJson.errors})
}
});
}

0 comments on commit 9dd1728

Please sign in to comment.