Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996081
handle-error.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
815 B
Referenced Files
None
Subscribers
None
handle-error.ts
View Options
import
SealiousError
from
"../response/errors.js"
;
import
type
{
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
Tue, Dec 24, 09:20 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557067
Default Alt Text
handle-error.ts (815 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment