-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
50 lines (42 loc) · 1.21 KB
/
error.go
File metadata and controls
50 lines (42 loc) · 1.21 KB
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
/*
* File Created: Friday, 28th July 2023 6:23:33 pm
* Author: Abdul Hamid (abdul.surel@gmail.com)
*
* Copyright (c) 2023 Author
*/
package durianpay
import "encoding/json"
const (
ErrorCodeSDK = "SDK_ERROR"
ErrorCodeDPAYInternalError = "DPAY_INTERNAL_ERROR"
ErrorCodeDPAYUnauthorizedAccess = "DPAY_UNAUTHORIZED_ACCESS"
ErrorCodeDPAYInvalidRequest = "DPAY_INVALID_REQUEST"
)
// Error is commons response error DurianPay
type Error struct {
StatusCode int // Response from http status code
Error string `json:"error"`
ErrorCode string `json:"error_code"`
Errors []Errors `json:"errors"`
Message string `json:"message"`
ResponseCode string `json:"response_code"` // ResponseCode currenty only present for Invoice API
}
type Errors struct {
Field string `json:"field"`
Message string `json:"message"`
}
func FromSDKError(err error) *Error {
return &Error{
Error: err.Error(),
ErrorCode: ErrorCodeSDK,
Message: err.Error(),
}
}
func FromAPI(statusCode int, responseBody []byte) *Error {
tempErr := Error{StatusCode: statusCode}
err := json.Unmarshal(responseBody, &tempErr)
if err != nil {
return FromSDKError(err)
}
return &tempErr
}