-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.ts
56 lines (51 loc) · 1.52 KB
/
index.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
import 'angular';
import 'angular-messages';
import uirouter from '@uirouter/angularjs';
import { HttpStatusCode } from '@ledge/types/http';
import { NgApp } from './src/app';
import { inputs } from './src/inputs';
import { misc } from './src/misc';
export const app = new NgApp()
.addComponents(inputs)
.addComponents(misc)
.addDependencies(['ngMessages', uirouter])
.addHttpInterceptor({
responseError(err) {
const { status, statusText, data, resource: url } = err;
switch (status) {
case HttpStatusCode.NotFound:
app.log.error(`Route '${url}' not found`);
break;
case HttpStatusCode.BadRequest:
if (typeof data === 'string') {
app.log.error(data);
} else if (data?.toString() === '[object Object]') {
app.log.error(Object.keys(data).map(x => `${x}: ${data[x]}`).join('\n\n'));
}
break;
case HttpStatusCode.Unauthorized:
case HttpStatusCode.Forbidden:
case HttpStatusCode.InternalServerError:
app.log.warning(statusText);
break;
case -1:
app.log.warning('Server timed out.');
break;
default:
app.log.error(`The request to '${url}' returned an error (code: ${status})`);
break;
}
return err;
},
});
export * from './src/app';
export * from './src/attributes';
export * from './src/controller';
export * from './src/http';
export * from './src/logger';
export * from './src/modal';
export * from './src/options';
export * from './src/router';
export * from './src/service';
export * from './src/inputs';
export * from './src/misc';