@@ -19,9 +19,9 @@ go get github.com/tiendc/go-apperrors
1919
2020## Usage
2121
22- ### Basic
22+ ### General usage
2323
24- - Initializes ` go-apperrors ` at program startup
24+ ** Initializes ` go-apperrors ` at program startup**
2525
2626``` go
2727import gae " github.com/tiendc/go-apperrors"
@@ -39,7 +39,7 @@ func main() {
3939}
4040```
4141
42- - Defines your errors
42+ ** Defines your errors**
4343
4444``` go
4545// It is recommended to add a new directory for placing app errors.
7070)
7171```
7272
73- - Handles errors in your main processing code
73+ ** Handles errors in your main processing code**
7474
7575``` go
7676// There are some use cases as below.
@@ -99,7 +99,7 @@ if `user.ID` is not in `project.userIDs` {
9999}
100100```
101101
102- - Handles validation errors
102+ ** Handles validation errors**
103103
104104``` go
105105// Validation is normally performed when you parse requests from client.
@@ -132,42 +132,42 @@ func (req UpdateProjectReq) Validate() gae.ValidationError {
132132}
133133```
134134
135- - Handles errors before returning them to client
135+ ** Handles errors before returning them to client**
136136
137137``` go
138138// In the base handler, implements function `RenderError()`
139- func RenderError (err error , requestWriter Writer ) {
140- // Gets language from request, you can use util `gae.ParseAcceptLanguage()`
139+ func RenderError (err error ) {
140+ // Gets language from request, you can use `gae.ParseAcceptLanguage()`
141141 lang := parseLanguageFromRequest ()
142142
143143 // Call goapperrors.Build
144144 buildResult := gae.Build (err, lang)
145145
146- // Log error to Sentry or a similar service
146+ // Logs error to Sentry or a similar service
147147 if buildResult.ErrorInfo .LogLevel != gae.LogLevelNone {
148148 logErrorToSentry (err, buildResult.ErrorInfo .LogLevel )
149149 }
150150
151151 // Sends the error as JSON to client
152- requestWriter .SendJSON (buildResult.ErrorInfo )
152+ response .SendJSON (buildResult.ErrorInfo )
153153}
154154
155155// In your specific handler, for instance, project handler
156- func (h ProjectHandler ) UpdateProject (httpReq ) {
157- req , err := parseAndValidateRequest (httpReq)
156+ func (h ProjectHandler ) UpdateProject () {
157+ updateProjectReq , err := parseAndValidateRequest (httpReq)
158158 if err != nil {
159159 baseHandler.RenderError (err)
160160 return
161161 }
162162
163- resp , err := useCase.UpdateProject (req )
163+ resp , err := useCase.UpdateProject (updateProjectReq )
164164 if err != nil {
165165 baseHandler.RenderError (err)
166166 return
167167 }
168168
169169 // Send result to client
170- requestWriter .SendJSON (resp)
170+ response .SendJSON (resp)
171171}
172172```
173173
0 commit comments