File: client_error.go

package info (click to toggle)
rdap 0.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 608 kB
  • sloc: makefile: 4
file content (53 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.

package rdap

import (
	"fmt"
	"strings"
)

type ClientErrorType uint

const (
	_ ClientErrorType = iota

	InputError
	BootstrapNotSupported
	BootstrapNoMatch
	WrongResponseType
	NoWorkingServers
	ObjectDoesNotExist
	RDAPServerError
)

type ClientError struct {
	Type ClientErrorType
	Text string
}

func (c ClientError) Error() string {
	return c.Text
}

func isClientError(t ClientErrorType, err error) bool {
	if ce, ok := err.(*ClientError); ok {
		if ce.Type == t {
			return true
		}
	}

	return false
}

func clientErrorFromRDAPError(e *Error) *ClientError {
	return &ClientError{
		Type: RDAPServerError,
		Text: fmt.Sprintf("Server returned error code %d, title='%s', description='%s'",
			e.ErrorCode,
			e.Title,
			strings.Join(e.Description, " ")),
	}
}