@casual-simulation/aux-common
Version:
Common library for AUX projects
169 lines • 5.4 kB
JavaScript
/**
* Gets the status code that should be used for the given response.
* @param response The response.
*/
export function getStatusCode(response) {
if (response.success === false) {
if (response.errorCode === 'not_logged_in') {
return 401;
}
else if (response.errorCode === 'not_supported') {
return 501;
}
else if (response.errorCode === 'data_not_found') {
return 404;
}
else if (response.errorCode === 'data_too_large') {
return 400;
}
else if (response.errorCode === 'record_not_found') {
return 404;
}
else if (response.errorCode === 'file_not_found') {
return 404;
}
else if (response.errorCode === 'session_not_found') {
return 404;
}
else if (response.errorCode === 'operation_not_found') {
return 404;
}
else if (response.errorCode === 'studio_not_found') {
return 404;
}
else if (response.errorCode === 'user_not_found') {
return 404;
}
else if (response.errorCode === 'session_already_revoked') {
return 200;
}
else if (response.errorCode === 'invalid_code') {
return 403;
}
else if (response.errorCode === 'invalid_key') {
return 403;
}
else if (response.errorCode === 'invalid_record_key') {
return 403;
}
else if (response.errorCode === 'invalid_request') {
return 403;
}
else if (response.errorCode === 'invalid_origin') {
return 403;
}
else if (response.errorCode === 'session_expired') {
return 401;
}
else if (response.errorCode === 'unacceptable_address') {
return 400;
}
else if (response.errorCode === 'unacceptable_user_id') {
return 400;
}
else if (response.errorCode === 'unacceptable_code') {
return 400;
}
else if (response.errorCode === 'unacceptable_session_key') {
return 400;
}
else if (response.errorCode === 'unacceptable_session_id') {
return 400;
}
else if (response.errorCode === 'unacceptable_request_id') {
return 400;
}
else if (response.errorCode === 'unacceptable_ip_address') {
return 500;
}
else if (response.errorCode === 'unacceptable_address_type') {
return 400;
}
else if (response.errorCode === 'unacceptable_expire_time') {
return 400;
}
else if (response.errorCode === 'unacceptable_request') {
return 400;
}
else if (response.errorCode === 'address_type_not_supported') {
return 501;
}
else if (response.errorCode === 'invalid_webhook_target') {
return 501;
}
else if (response.errorCode === 'server_error') {
return 500;
}
else if (response.errorCode === 'unauthorized_to_create_record_key') {
return 403;
}
else if (response.errorCode === 'price_does_not_match') {
return 412;
}
else if (response.errorCode === 'user_is_banned') {
return 403;
}
else if (response.errorCode === 'rate_limit_exceeded') {
return 429;
}
else if (response.errorCode === 'not_authorized') {
return 403;
}
else if (response.errorCode === 'not_subscribed') {
return 403;
}
else if (response.errorCode === 'invalid_subscription_tier') {
return 403;
}
else if (response.errorCode === 'record_already_exists') {
return 403;
}
else if (response.errorCode === 'subscription_limit_reached') {
return 403;
}
else if (response.errorCode === 'inst_not_found') {
return 404;
}
else if (response.errorCode === 'action_not_supported') {
return 500;
}
else if (response.errorCode === 'policy_not_found') {
return 404;
}
else if (response.errorCode === 'comId_not_found') {
return 404;
}
else if (response.errorCode === 'comId_already_taken') {
return 409;
}
else if (response.errorCode === 'permission_not_found') {
return 404;
}
else if (response.errorCode === 'message_not_found') {
return 404;
}
else if (response.errorCode === 'not_found') {
return 404;
}
else if (response.errorCode === 'invalid_connection_state') {
return 500;
}
else if (response.errorCode === 'user_already_exists') {
return 400;
}
else if (response.errorCode === 'hume_api_error') {
return 500;
}
else if (response.errorCode === 'took_too_long') {
return 504;
}
else if (response.errorCode === 'service_unavailable') {
return 503;
}
else {
return 400;
}
}
return 200;
}
//# sourceMappingURL=ErrorCodes.js.map