-
Notifications
You must be signed in to change notification settings - Fork 1
/
Errors.ts
69 lines (61 loc) · 1.95 KB
/
Errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace Moysklad.Errors {
export class MoyskladError extends Error {
constructor(message: string) {
super(message)
this.name = this.constructor.name
}
}
export class MoyskladArgumentError extends MoyskladError {
constructor(arg: any, argName: string, info?: string) {
const argVal = JSON.stringify(arg)?.substr(0, 100)
super(
`Некорректный аргумент ${argName}${
info ? ` (${info})` : ''
} - ${argVal}`
)
}
}
export class MoyskladRequestError extends MoyskladError {
public url: string
public status: number
public statusText: string | null
public request: GoogleAppsScript.URL_Fetch.URLFetchRequest
public response: GoogleAppsScript.URL_Fetch.HTTPResponse
constructor(
message: string,
request: GoogleAppsScript.URL_Fetch.URLFetchRequest,
response: GoogleAppsScript.URL_Fetch.HTTPResponse
) {
super(message)
this.url = request.url
this.status = response.getResponseCode()
this.statusText = null
this.request = request
this.response = response
}
}
export class MoyskladApiError extends MoyskladRequestError
implements MoyskladErrorInfo {
public error: string
public code: number
public moreInfo: string
public line?: number
public column?: number
public errors: MoyskladErrorInfo[]
constructor(
errors: MoyskladErrorInfo[],
request: GoogleAppsScript.URL_Fetch.URLFetchRequest,
response: GoogleAppsScript.URL_Fetch.HTTPResponse
) {
const error = errors[0]
const message = error.error || 'Неизвестная ошибка API МойСклад'
super(message, request, response)
this.error = error.error
this.code = error.code
this.moreInfo = error.moreInfo
if (error.line != null) this.line = error.line
if (error.column != null) this.column = error.column
this.errors = errors
}
}
}