]>
Commit | Line | Data |
---|---|---|
107c1cdb ND |
1 | // Copyright 2011 Google Inc. All rights reserved. |
2 | // Use of this source code is governed by the Apache 2.0 | |
3 | // license that can be found in the LICENSE file. | |
4 | ||
5 | // This file provides error functions for common API failure modes. | |
6 | ||
7 | package appengine | |
8 | ||
9 | import ( | |
10 | "fmt" | |
11 | ||
12 | "google.golang.org/appengine/internal" | |
13 | ) | |
14 | ||
15 | // IsOverQuota reports whether err represents an API call failure | |
16 | // due to insufficient available quota. | |
17 | func IsOverQuota(err error) bool { | |
18 | callErr, ok := err.(*internal.CallError) | |
19 | return ok && callErr.Code == 4 | |
20 | } | |
21 | ||
22 | // MultiError is returned by batch operations when there are errors with | |
23 | // particular elements. Errors will be in a one-to-one correspondence with | |
24 | // the input elements; successful elements will have a nil entry. | |
25 | type MultiError []error | |
26 | ||
27 | func (m MultiError) Error() string { | |
28 | s, n := "", 0 | |
29 | for _, e := range m { | |
30 | if e != nil { | |
31 | if n == 0 { | |
32 | s = e.Error() | |
33 | } | |
34 | n++ | |
35 | } | |
36 | } | |
37 | switch n { | |
38 | case 0: | |
39 | return "(0 errors)" | |
40 | case 1: | |
41 | return s | |
42 | case 2: | |
43 | return s + " (and 1 other error)" | |
44 | } | |
45 | return fmt.Sprintf("%s (and %d other errors)", s, n-1) | |
46 | } |