Commit 1797b891 authored by adrtel's avatar adrtel

- Beautified code of all im_rest_error calls

  to be preceeded by a "return"
parent f595a9f1
......@@ -63,7 +63,7 @@ ad_proc -private im_rest_get_object_type {
set table_name [lindex $otype_info 0 0]
set id_column [lindex $otype_info 0 1]
if {"" == $table_name} {
im_rest_error -format $org_format -http_status 500 -message "Invalid DynField configuration: Object type '$rest_otype' doesn't have a table_name specified in table acs_object_types."
return [im_rest_error -format $org_format -http_status 500 -message "Invalid DynField configuration: Object type '$rest_otype' doesn't have a table_name specified in table acs_object_types."]
}
# Deal with ugly situation that usre_id is defined multiple times for object_type=user
if {"users" == $table_name} { set id_column "person_id" }
......@@ -169,8 +169,7 @@ ad_proc -private im_rest_get_object_type {
foreach where_clause $where_clause_list {
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $org_format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $org_format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
}
......@@ -240,12 +239,10 @@ ad_proc -private im_rest_get_object_type {
# Write out error message only if the user has specified a single object to check. Otherwise just skip.
if {!$read_p && "" != $org_rest_oid} {
im_rest_error -format $org_format -http_status 403 -message "User #$rest_user_id does not have read access to object #$org_rest_oid"
return
return [im_rest_error -format $org_format -http_status 403 -message "User #$rest_user_id does not have read access to object #$org_rest_oid"]
}
} err_msg]} {
im_rest_error -format $org_format -http_status 500 -message "Internal error: $err_msg"
return
return [im_rest_error -format $org_format -http_status 500 -message "Internal error: $err_msg"]
}
}
if {!$read_p} { continue }
......@@ -325,8 +322,7 @@ ad_proc -private im_rest_get_im_invoice_items {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -448,8 +444,7 @@ ad_proc -private im_rest_get_im_hours {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -574,8 +569,7 @@ ad_proc -private im_rest_get_im_hour_intervals {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -687,8 +681,7 @@ ad_proc -private im_rest_get_im_timesheet_task_dependencies {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -810,8 +803,7 @@ ad_proc -private im_rest_get_im_categories {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -923,8 +915,7 @@ ad_proc -private im_rest_get_im_dynfield_attributes {
# Check that the query is a valid SQL where clause
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......@@ -1047,8 +1038,7 @@ ad_proc -private im_rest_get_im_indicator_result_interval {
set valid_sql_where [im_rest_valid_sql -string $where_clause -variables $valid_vars]
if {!$valid_sql_where} {
im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"
return
return [im_rest_error -format $format -http_status 403 -message "The specified query is not a valid SQL where clause: '$where_clause'"]
}
if {"" != $where_clause} { set where_clause "and $where_clause" }
......
......@@ -51,7 +51,7 @@ ad_proc -private im_rest_post_object_type {
# Extract the object's id from the return array and write into object_id in case a client needs the info
if {![info exists hash_array(rest_oid)]} {
# Probably after an im_rest_error
# Probably after a rest_error
ns_log Error "im_rest_post_object_type: Didn't find hash_array(rest_oid): This should never happened"
}
set rest_oid $hash_array(rest_oid)
......@@ -87,8 +87,7 @@ ad_proc -private im_rest_post_object_type {
} else {
ns_log Notice "im_rest_post_object_type: Create for '$rest_otype' not implemented yet"
im_rest_error -format $format -http_status 404 -message "Object creation for object type '$rest_otype' not implemented yet."
return
return [im_rest_error -format $format -http_status 404 -message "Object creation for object type '$rest_otype' not implemented yet."]
}
return
}
......@@ -121,8 +120,7 @@ ad_proc -private im_rest_post_object {
set write_p [im_object_permission -object_id $rest_otype_id -user_id $rest_user_id -privilege "write"]
if {!$write_p} {
set msg "im_rest_post_object: User #$rest_user_id has no 'write' permission in general on object type '$rest_otype' - please check your REST permissions"
im_rest_error -format $format -http_status 403 -message $msg
return
return [im_rest_error -format $format -http_status 403 -message $msg]
}
# Check if there is an object type specific permission checker
......@@ -136,8 +134,7 @@ ad_proc -private im_rest_post_object {
ns_log Notice "im_rest_post_object: Did not find permission proc ${rest_otype}_permissions - POST permissions denied"
}
if {!$write_p} {
im_rest_error -format $format -http_status 403 -message "User #$rest_user_id has no write permission on object #$rest_oid"
return
return [im_rest_error -format $format -http_status 403 -message "User #$rest_user_id has no write permission on object #$rest_oid"]
}
# Check if there is a customized version of this post handler
......@@ -393,8 +390,7 @@ ad_proc -private im_rest_delete_object {
}
}
if {!$admin_p} {
im_rest_error -format $format -http_status 403 -message "User #$rest_user_id has no 'admin' permission to perform DELETE on object #$rest_oid"
return
return [im_rest_error -format $format -http_status 403 -message "User #$rest_user_id has no 'admin' permission to perform DELETE on object #$rest_oid"]
}
# Deal with certain subtypes
......@@ -442,8 +438,7 @@ ad_proc -private im_rest_delete_object {
# Try to destruct the object
if {!$destroyed_p} {
im_rest_error -format $format -http_status 404 -message "DELETE for object #$rest_oid of type \"$rest_otype\" created errors: $destroyed_err_msg"
return
return [im_rest_error -format $format -http_status 404 -message "DELETE for object #$rest_oid of type \"$rest_otype\" created errors: $destroyed_err_msg"]
}
# The delete was successful - return a suitable message.
......
......@@ -594,7 +594,7 @@ ad_proc -public im_rest_error {
} {
Returns a suitable REST error message
} {
ns_log Notice "im_rest_error: http_status=$http_status, format=$format, message=$message"
ns_log Error "im_rest_error: http_status=$http_status, format=$format, message=$message"
set url [im_url_with_query]
switch $http_status {
......
......@@ -72,7 +72,8 @@ if {[catch {
ns_log Error "project-task-tree-action: Reporting back error: [ad_print_stack_trace]"
set success "false"
set message [im_rest_error -format json -http_status 404 -message "Internal Error: [ad_print_stack_trace]"]
set message $err_msg
im_rest_error -format json -http_status 404 -message "Internal Error: [ad_print_stack_trace]"
}
......@@ -84,3 +85,6 @@ if {[catch {
# However, we need to call this in order to update the main
# project. => Maybe limit to that in the call?
im_timesheet_project_advance $project_id
# ToDo: Return JSON??
......@@ -26,8 +26,7 @@ if {![info exists query_hash(widget_id)]} {
ad_script_abort
}
xml {
im_rest_error -http_status 406 -message "Parameter 'widget_id' missing, please specify"
return
return [im_rest_error -http_status 406 -message "Parameter 'widget_id' missing, please specify"]
}
}
}
......@@ -40,8 +39,7 @@ if {0 == $user_id} {
ad_script_abort
}
xml {
im_rest_error -http_status 401 -message "Not authenticated"
return
return [im_rest_error -http_status 401 -message "Not authenticated"]
}
}
}
......@@ -63,8 +61,7 @@ if {![info exists widget_name]} {
ad_script_abort
}
xml {
im_rest_error -http_status 406 -message "Invalid 'widget_id'"
return
return [im_rest_error -http_status 406 -message "Invalid 'widget_id'"]
}
}
}
......@@ -89,8 +86,7 @@ switch $tcl_widget {
ad_script_abort
}
xml {
im_rest_error -http_status 406 -message $message
return
return [im_rest_error -http_status 406 -message $message]
}
}
}
......@@ -130,4 +126,4 @@ switch $format {
# End of HTML stuff
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment