001/* 002 * Copyright 2015-2018 the original author or authors 003 * 004 * This software is licensed under the Apache License, Version 2.0, 005 * the GNU Lesser General Public License version 2 or later ("LGPL") 006 * and the WTFPL. 007 * You may choose either license to govern your use of this software only 008 * upon the condition that you accept all of the terms of either 009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL. 010 */ 011package org.minidns; 012 013import java.io.IOException; 014 015import org.minidns.dnsmessage.DnsMessage; 016 017public abstract class MiniDnsException extends IOException { 018 /** 019 * 020 */ 021 private static final long serialVersionUID = 1L; 022 023 protected MiniDnsException(String message) { 024 super(message); 025 } 026 027 public static class IdMismatch extends MiniDnsException { 028 029 /** 030 * 031 */ 032 private static final long serialVersionUID = 1L; 033 034 private final DnsMessage request; 035 private final DnsMessage response; 036 037 public IdMismatch(DnsMessage request, DnsMessage response) { 038 super(getString(request, response)); 039 assert (request.id != response.id); 040 this.request = request; 041 this.response = response; 042 } 043 044 public DnsMessage getRequest() { 045 return request; 046 } 047 048 public DnsMessage getResponse() { 049 return response; 050 } 051 052 private static String getString(DnsMessage request, DnsMessage response) { 053 return "The response's ID doesn't matches the request ID. Request: " + request.id + ". Response: " + response.id; 054 } 055 } 056 057 public static class NullResultException extends MiniDnsException { 058 059 /** 060 * 061 */ 062 private static final long serialVersionUID = 1L; 063 064 private final DnsMessage request; 065 066 public NullResultException(DnsMessage request) { 067 super("The request yielded a 'null' result while resolving."); 068 this.request = request; 069 } 070 071 public DnsMessage getRequest() { 072 return request; 073 } 074 } 075}