github.com/Axway/agent-sdk@v1.1.101/pkg/apic/apiserver/clients/api/v1/errors.go (about)

     1  package v1
     2  
     3  import (
     4  	"fmt"
     5  	"html/template"
     6  	"strings"
     7  
     8  	apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
     9  )
    10  
    11  // Errors -
    12  type Errors []apiv1.Error
    13  
    14  // Error -
    15  func (e Errors) Error() string {
    16  	b := &strings.Builder{}
    17  
    18  	b.WriteRune('[')
    19  	for i, err := range e {
    20  		b.WriteString(fmt.Sprintf("{\"status\": %d, \"detail\": \"%s\"}", err.Status, template.JSEscapeString(err.Detail)))
    21  		if i < len(e)-1 {
    22  			b.WriteRune(',')
    23  		}
    24  	}
    25  	b.WriteRune(']')
    26  
    27  	return b.String()
    28  }
    29  
    30  // ConflictError -
    31  type ConflictError struct {
    32  	Errors
    33  }
    34  
    35  // Error -
    36  func (nf ConflictError) Error() string {
    37  	return fmt.Sprintf("conflict: %s", nf.Errors)
    38  }
    39  
    40  // NotFoundError -
    41  type NotFoundError struct {
    42  	Errors
    43  }
    44  
    45  // Error -
    46  func (nf NotFoundError) Error() string {
    47  	return fmt.Sprintf("not found: %s", nf.Errors)
    48  }
    49  
    50  // InternalServerError -
    51  type InternalServerError struct {
    52  	Errors
    53  }
    54  
    55  // Error -
    56  func (nf InternalServerError) Error() string {
    57  	return fmt.Sprintf("internal server error: %s", nf.Errors)
    58  }
    59  
    60  // ForbiddenError -
    61  type ForbiddenError struct {
    62  	Errors
    63  }
    64  
    65  // Error -
    66  func (nf ForbiddenError) Error() string {
    67  	return fmt.Sprintf("forbidden: %s", nf.Errors)
    68  }
    69  
    70  // UnauthorizedError -
    71  type UnauthorizedError struct {
    72  	Errors
    73  }
    74  
    75  // Error -
    76  func (nf UnauthorizedError) Error() string {
    77  	return fmt.Sprintf("unauthorized: %s", nf.Errors)
    78  }
    79  
    80  // BadRequestError -
    81  type BadRequestError struct {
    82  	Errors
    83  }
    84  
    85  // Error -
    86  func (nf BadRequestError) Error() string {
    87  	return fmt.Sprintf("bad request: %s", nf.Errors)
    88  }
    89  
    90  // UnexpectedError -
    91  type UnexpectedError struct {
    92  	code int
    93  	Errors
    94  }
    95  
    96  // Error -
    97  func (nf UnexpectedError) Error() string {
    98  	return fmt.Sprintf("unexpected code %d: %s", nf.code, nf.Errors)
    99  }