diff --git a/src/api/create_dns_record.ts b/src/api/create_dns_record.ts index 33e32ae..1aa9970 100644 --- a/src/api/create_dns_record.ts +++ b/src/api/create_dns_record.ts @@ -1,3 +1,5 @@ +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'; @@ -5,5 +7,26 @@ 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}) + } + }); }