code.gitea.io/gitea@v1.22.3/models/user/error.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package user
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"code.gitea.io/gitea/modules/util"
    10  )
    11  
    12  // ErrUserAlreadyExist represents a "user already exists" error.
    13  type ErrUserAlreadyExist struct {
    14  	Name string
    15  }
    16  
    17  // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
    18  func IsErrUserAlreadyExist(err error) bool {
    19  	_, ok := err.(ErrUserAlreadyExist)
    20  	return ok
    21  }
    22  
    23  func (err ErrUserAlreadyExist) Error() string {
    24  	return fmt.Sprintf("user already exists [name: %s]", err.Name)
    25  }
    26  
    27  // Unwrap unwraps this error as a ErrExist error
    28  func (err ErrUserAlreadyExist) Unwrap() error {
    29  	return util.ErrAlreadyExist
    30  }
    31  
    32  // ErrUserNotExist represents a "UserNotExist" kind of error.
    33  type ErrUserNotExist struct {
    34  	UID  int64
    35  	Name string
    36  }
    37  
    38  // IsErrUserNotExist checks if an error is a ErrUserNotExist.
    39  func IsErrUserNotExist(err error) bool {
    40  	_, ok := err.(ErrUserNotExist)
    41  	return ok
    42  }
    43  
    44  func (err ErrUserNotExist) Error() string {
    45  	return fmt.Sprintf("user does not exist [uid: %d, name: %s]", err.UID, err.Name)
    46  }
    47  
    48  // Unwrap unwraps this error as a ErrNotExist error
    49  func (err ErrUserNotExist) Unwrap() error {
    50  	return util.ErrNotExist
    51  }
    52  
    53  // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
    54  type ErrUserProhibitLogin struct {
    55  	UID  int64
    56  	Name string
    57  }
    58  
    59  // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
    60  func IsErrUserProhibitLogin(err error) bool {
    61  	_, ok := err.(ErrUserProhibitLogin)
    62  	return ok
    63  }
    64  
    65  func (err ErrUserProhibitLogin) Error() string {
    66  	return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
    67  }
    68  
    69  // Unwrap unwraps this error as a ErrPermission error
    70  func (err ErrUserProhibitLogin) Unwrap() error {
    71  	return util.ErrPermissionDenied
    72  }
    73  
    74  // ErrUserInactive represents a "ErrUserInactive" kind of error.
    75  type ErrUserInactive struct {
    76  	UID  int64
    77  	Name string
    78  }
    79  
    80  // IsErrUserInactive checks if an error is a ErrUserInactive
    81  func IsErrUserInactive(err error) bool {
    82  	_, ok := err.(ErrUserInactive)
    83  	return ok
    84  }
    85  
    86  func (err ErrUserInactive) Error() string {
    87  	return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
    88  }
    89  
    90  // Unwrap unwraps this error as a ErrPermission error
    91  func (err ErrUserInactive) Unwrap() error {
    92  	return util.ErrPermissionDenied
    93  }
    94  
    95  // ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error.
    96  type ErrUserIsNotLocal struct {
    97  	UID  int64
    98  	Name string
    99  }
   100  
   101  func (err ErrUserIsNotLocal) Error() string {
   102  	return fmt.Sprintf("user is not local type [uid: %d, name: %s]", err.UID, err.Name)
   103  }
   104  
   105  // IsErrUserIsNotLocal
   106  func IsErrUserIsNotLocal(err error) bool {
   107  	_, ok := err.(ErrUserIsNotLocal)
   108  	return ok
   109  }