Adding ErrorCode enum

This commit is contained in:
Fabian Stamm
2018-05-13 20:32:55 +02:00
parent eb4ae29f7e
commit 57c638316e
9 changed files with 58 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import { Parser } from "binary-parser"
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord } from "./types"
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord, ErrorCodes } from "./types"
const MAX_LABEL_SIZE = 63;
@ -193,6 +193,10 @@ export class Request implements Message {
this._questions = parseQuestions(this._header.QDCOUNT, bodyData);
}
error(error: ErrorCodes) {
this._header.RCODE = error;
}
send() {
this.sendCallback(this.serialize());
}

View File

@ -1,3 +1,21 @@
// 0 No error condition
// * 1 Format error - unable to interpret query
// * 2 Server failure - internal problem
// * 3 Name error - Only for authorative name server, domain name of query does not exist
// * 4 Not implemented - Request not supported
// * 5 Refused - Nameserver refuses request
// * 6 - 15 Reserved for future usage
// *
export enum ErrorCodes {
NoError = 0,
FormatError,
ServerFailure,
NameError,
NotImplemented,
Refused
}
export interface MessageHeader {
/**
* A 16 bit identifier assigned by the program that
@ -69,7 +87,7 @@ export interface MessageHeader {
* 5 Refused - Nameserver refuses request
* 6-15 Reserved for future usage
*/
RCODE: 0 | 1 | 2 | 3 | 4 | 5;
RCODE: ErrorCodes;
/**
* Number of entries in question section