github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/error.go (about) 1 // Copyright 2016 LINE Corporation 2 // 3 // LINE Corporation licenses this file to you under the Apache License, 4 // version 2.0 (the "License"); you may not use this file except in compliance 5 // with the License. You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package linebot 16 17 import ( 18 "bytes" 19 "errors" 20 "fmt" 21 ) 22 23 // errors 24 var ( 25 ErrInvalidSignature = errors.New("invalid signature") 26 ) 27 28 // APIError type 29 type APIError struct { 30 Code int 31 Response *ErrorResponse 32 } 33 34 // Error method 35 func (e *APIError) Error() string { 36 var buf bytes.Buffer 37 fmt.Fprintf(&buf, "linebot: APIError %d ", e.Code) 38 if e.Response != nil { 39 fmt.Fprintf(&buf, "%s", e.Response.Message) 40 for _, d := range e.Response.Details { 41 fmt.Fprintf(&buf, "\n[%s] %s", d.Property, d.Message) 42 } 43 } 44 return buf.String() 45 }