errors

package
v6.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Example
package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	"github.com/sabariramc/goserverbase/v6/errors"
)

func main() {
	err := &errors.CustomError{"goserverbase.test.error", "test error message", "test error data", "test error description", false}
	fmt.Println(err)
	herr := errors.HTTPError{StatusCode: http.StatusConflict, CustomError: err}
	data, _ := json.MarshalIndent(herr, "", "    ")
	fmt.Println(string(data))
}
Output:

{
    "errorCode": "goserverbase.test.error",
    "errorMessage": "test error message",
    "errorData": "test error data",
    "errorDescription": "test error description"
}
{
    "errorCode": "goserverbase.test.error",
    "errorMessage": "test error message",
    "errorData": "test error data",
    "errorDescription": "test error description",
    "statusCode": 409
}

Index

Examples

Constants

View Source
const ErrParse = "******************ERROR DURING MARSHAL OF FULL MESSAGE*******************"

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomError

type CustomError struct {
	ErrorCode        string      `json:"errorCode"`
	ErrorMessage     string      `json:"errorMessage"`
	ErrorData        interface{} `json:"errorData"`
	ErrorDescription interface{} `json:"errorDescription"`
	Notify           bool        `json:"-"`
}

CustomError represents a custom error with additional attributes.

func (CustomError) Error

func (e CustomError) Error() string

Error returns the JSON representation of the custom error.

func (CustomError) GetErrorResponse

func (e CustomError) GetErrorResponse() ([]byte, error)

GetErrorResponse returns the JSON representation of the error response.

type HTTPError

type HTTPError struct {
	*CustomError `json:",inline"`
	StatusCode   int `json:"statusCode"`
}

HTTPError represents an HTTP error with a custom error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL