forked from divan/gorilla-xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfault.go
52 lines (44 loc) · 1.56 KB
/
fault.go
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
// Copyright 2013 Ivan Danyliuk
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xml
import (
"fmt"
)
// Default Faults
// NOTE: XMLRPC spec doesn't specify any Fault codes.
// These codes seems to be widely accepted, and taken from the http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
var (
FaultInvalidParams = Fault{Code: -32602, String: "Invalid Method Parameters"}
FaultWrongArgumentsNumber = Fault{Code: -32602, String: "Wrong Arguments Number"}
FaultInternalError = Fault{Code: -32603, String: "Internal Server Error"}
FaultApplicationError = Fault{Code: -32500, String: "Application Error"}
FaultSystemError = Fault{Code: -32400, String: "System Error"}
FaultDecode = Fault{Code: -32700, String: "Parsing error: not well formed"}
)
// Fault represents XML-RPC Fault.
type Fault struct {
Code int `xml:"faultCode"`
String string `xml:"faultString"`
}
// Error satisifies error interface for Fault.
func (f Fault) Error() string {
return fmt.Sprintf("%d: %s", f.Code, f.String)
}
// Fault2XML is a quick 'marshalling' replacemnt for the Fault case.
func fault2XML(fault Fault) string {
buffer := "<methodResponse><fault>"
xml, _ := rpc2XML(fault)
buffer += xml
buffer += "</fault></methodResponse>"
return buffer
}
type faultValue struct {
Value value `xml:"value"`
}
// IsEmpty returns true if faultValue contain fault.
//
// faultValue should be a struct with 2 members.
func (f faultValue) IsEmpty() bool {
return len(f.Value.Struct) == 0
}