Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010473
handle-error.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
883 B
Referenced Files
None
Subscribers
None
handle-error.ts
View Options
import
error_to_boom
from
"./error-to-boom"
;
import
{
App
}
from
"../main"
;
import
SealiousError
from
"../response/errors"
;
import
{
Middleware
}
from
"@koa/router"
;
const
error_code_map
:
{
[
type
:
string
]
:
number
}
=
{
validation
:
403
,
value_exists
:
409
,
invalid_credentials
:
401
,
not_found
:
404
,
permission
:
401
,
bad_subject
:
404
,
bad_subject_action
:
405
,
field_does_not_support_attachments
:
405
,
};
export
default
function
handleError
()
:
Middleware
{
return
async
function
(
ctx
,
next
)
{
try
{
await
next
();
}
catch
(
error
)
{
ctx
.
$app
.
Logger
.
error
(
"HTTP ERR"
,
"Responding with error"
,
error
);
if
(
error
instanceof
SealiousError
&&
error
.
is_user_fault
)
{
ctx
.
status
=
error_code_map
[
error
.
type
]
||
500
;
ctx
.
body
=
error
.
toObject
();
}
else
{
ctx
.
status
=
500
;
ctx
.
body
=
{
message
:
"Server error"
};
console
.
error
(
error
);
}
}
};
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:43 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
662866
Default Alt Text
handle-error.ts (883 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment