github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/http/errors.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package http
     4  
     5  import (
     6  	er "../error"
     7  	"../protocol"
     8  )
     9  
    10  const domainEnglish = "HTTP"
    11  const domainPersian = "HTTP"
    12  
    13  // Declare package errors
    14  var (
    15  	ErrNoConnection         er.Error
    16  	ErrPacketTooShort       er.Error
    17  	ErrPacketTooLong        er.Error
    18  	ErrParseMethod          er.Error
    19  	ErrParseURI             er.Error
    20  	ErrParseVersion         er.Error
    21  	ErrParseStatusCode      er.Error
    22  	ErrParseReasonPhrase    er.Error
    23  	ErrParseHeaderTooLarge  er.Error
    24  	ErrCookieBadName        er.Error
    25  	ErrCookieBadValue       er.Error
    26  	ErrCookieBadPath        er.Error
    27  	ErrCookieBadDomain      er.Error
    28  	ErrNotFound             er.Error
    29  	ErrUnsupportedMediaType er.Error
    30  )
    31  
    32  func init() {
    33  	ErrNoConnection.Init("domain/http.protocol.error; name=no-connection")
    34  	ErrNoConnection.SetDetail(protocol.LanguageEnglish, domainEnglish,
    35  		"No Connection",
    36  		"There is no connection to peer(server or client) to proccess request",
    37  		"",
    38  		"",
    39  		nil)
    40  	ErrNoConnection.SetDetail(protocol.LanguagePersian, domainPersian,
    41  		"عدم وجود ارتباط",
    42  		"هیچ راه ارتباطی با رایانه مقصد برای پردازش درخواست مورد نظر وجود ندارد",
    43  		"",
    44  		"",
    45  		nil)
    46  	ErrNoConnection.RegisterError()
    47  
    48  	ErrPacketTooShort.Init("domain/http.protocol.error; name=packet-too-short")
    49  	ErrPacketTooShort.SetDetail(protocol.LanguageEnglish, domainEnglish,
    50  		"Packet Too Short",
    51  		"Received HTTP packet size is shorter than expected and can't use",
    52  		"",
    53  		"",
    54  		nil)
    55  	ErrPacketTooShort.RegisterError()
    56  
    57  	ErrPacketTooLong.Init("domain/http.protocol.error; name=packet-too-long")
    58  	ErrPacketTooLong.SetDetail(protocol.LanguageEnglish, domainEnglish,
    59  		"Packet Too Long",
    60  		"Received HTTP packet size is larger than expected and can't use",
    61  		"",
    62  		"",
    63  		nil)
    64  	ErrPacketTooLong.RegisterError()
    65  
    66  	ErrParseMethod.Init("domain/http.protocol.error; name=parse-method")
    67  	ErrParseMethod.SetDetail(protocol.LanguageEnglish, domainEnglish,
    68  		"Parse Method",
    69  		"Parsing received HTTP packet encounter unknown situation in Method part",
    70  		"",
    71  		"",
    72  		nil)
    73  	ErrParseMethod.RegisterError()
    74  
    75  	ErrParseURI.Init("domain/http.protocol.error; name=parse-uri")
    76  	ErrParseURI.SetDetail(protocol.LanguageEnglish, domainEnglish,
    77  		"Parse URI",
    78  		"Parsing received HTTP packet encounter unknown situation in URI part",
    79  		"",
    80  		"",
    81  		nil)
    82  	ErrParseURI.RegisterError()
    83  
    84  	ErrParseVersion.Init("domain/http.protocol.error; name=parse-version")
    85  	ErrParseVersion.SetDetail(protocol.LanguageEnglish, domainEnglish,
    86  		"Parse Version",
    87  		"Parsing received HTTP packet encounter unknown situation in Version part",
    88  		"",
    89  		"",
    90  		nil)
    91  	ErrParseVersion.RegisterError()
    92  
    93  	ErrParseStatusCode.Init("domain/http.protocol.error; name=parse-status-code")
    94  	ErrParseStatusCode.SetDetail(protocol.LanguageEnglish, domainEnglish,
    95  		"Parse Status Code",
    96  		"Parsing received HTTP packet encounter unknown situation in StatusCode part",
    97  		"",
    98  		"",
    99  		nil)
   100  	ErrParseStatusCode.RegisterError()
   101  
   102  	ErrParseReasonPhrase.Init("domain/http.protocol.error; name=parse-reason-phrase")
   103  	ErrParseReasonPhrase.SetDetail(protocol.LanguageEnglish, domainEnglish,
   104  		"Parse Reason Phrase",
   105  		"Parsing received HTTP packet encounter unknown situation in ReasonPhrase part",
   106  		"",
   107  		"",
   108  		nil)
   109  	ErrParseReasonPhrase.RegisterError()
   110  
   111  	ErrParseHeaderTooLarge.Init("domain/http.protocol.error; name=parse-header-too-large")
   112  	ErrParseHeaderTooLarge.SetDetail(protocol.LanguageEnglish, domainEnglish,
   113  		"Parse Header Too Large",
   114  		"Parsing received HTTP packet encounter situation that header part of http packet is larger than expected",
   115  		"",
   116  		"",
   117  		nil)
   118  	ErrParseHeaderTooLarge.RegisterError()
   119  
   120  	ErrCookieBadName.Init("domain/http.protocol.error; name=cookie-bad-name")
   121  	ErrCookieBadName.SetDetail(protocol.LanguageEnglish, domainEnglish,
   122  		"Cookie Bad Name",
   123  		"Cookie name include illegal charecter by related RFC",
   124  		"",
   125  		"",
   126  		nil)
   127  	ErrCookieBadName.RegisterError()
   128  
   129  	ErrCookieBadValue.Init("domain/http.protocol.error; name=cookie-bad-value")
   130  	ErrCookieBadValue.SetDetail(protocol.LanguageEnglish, domainEnglish,
   131  		"Cookie Bad Value",
   132  		"Cookie value include illegal charecter by related RFC",
   133  		"",
   134  		"",
   135  		nil)
   136  	ErrCookieBadValue.RegisterError()
   137  
   138  	ErrCookieBadPath.Init("domain/http.protocol.error; name=cookie-bad-path")
   139  	ErrCookieBadPath.SetDetail(protocol.LanguageEnglish, domainEnglish,
   140  		"Cookie Bad Path",
   141  		"Cookie path include illegal charecter by related RFC",
   142  		"",
   143  		"",
   144  		nil)
   145  	ErrCookieBadPath.RegisterError()
   146  
   147  	ErrCookieBadDomain.Init("domain/http.protocol.error; name=cookie-bad-domain")
   148  	ErrCookieBadDomain.SetDetail(protocol.LanguageEnglish, domainEnglish,
   149  		"Cookie Bad Domain",
   150  		"Cookie domain is not valid by related RFC",
   151  		"",
   152  		"",
   153  		nil)
   154  	ErrCookieBadDomain.RegisterError()
   155  
   156  	ErrNotFound.Init("domain/http.protocol.error; name=not-found")
   157  	ErrNotFound.SetDetail(protocol.LanguageEnglish, domainEnglish,
   158  		"Not Found",
   159  		"Requested HTTP URI Service is not found in this instance of app",
   160  		"",
   161  		"",
   162  		nil)
   163  	ErrNotFound.RegisterError()
   164  
   165  	ErrUnsupportedMediaType.Init("domain/http.protocol.error; name=unsupported-media-type")
   166  	ErrUnsupportedMediaType.SetDetail(protocol.LanguageEnglish, domainEnglish,
   167  		"Unsupported Media Type",
   168  		"Refuse to accept the request or response because the payload format or encoding is in an unsupported format",
   169  		"",
   170  		"",
   171  		nil)
   172  	ErrUnsupportedMediaType.RegisterError()
   173  }