@@ -98,6 +98,11 @@ async function handle_request(req, res) {
98
98
await http_utils . read_and_parse_body ( req , options ) ;
99
99
100
100
const op_name = parse_op_name ( req , req . body . action ) ;
101
+ const op = IAM_OPS [ op_name ] ;
102
+ if ( ! op || ! op . handler ) {
103
+ dbg . error ( 'IAM (NotImplemented)' , op_name , req . method , req . originalUrl ) ;
104
+ throw new IamError ( IamError . NotImplemented ) ;
105
+ }
101
106
req . op_name = op_name ;
102
107
103
108
http_utils . authorize_session_token ( req , headers_options ) ;
@@ -106,12 +111,6 @@ async function handle_request(req, res) {
106
111
107
112
dbg . log1 ( 'IAM REQUEST' , req . method , req . originalUrl , 'op' , op_name , 'request_id' , req . request_id , req . headers ) ;
108
113
109
- const op = IAM_OPS [ op_name ] ;
110
- if ( ! op || ! op . handler ) {
111
- dbg . error ( 'IAM TODO (NotImplemented)' , op_name , req . method , req . originalUrl ) ;
112
- throw new IamError ( IamError . NotImplemented ) ;
113
- }
114
-
115
114
const reply = await op . handler ( req , res ) ;
116
115
add_response_metadata_if_not_exists ( reply , req . request_id ) ; // unique to IAM
117
116
http_utils . send_reply ( req , res , reply , {
@@ -171,9 +170,9 @@ function handle_error(req, res, err) {
171
170
// we only support request with specific type
172
171
function verify_op_request_body_type ( req ) {
173
172
const headers = req . headers [ 'content-type' ] ;
174
- if ( ! headers . includes ( http_utils . CONTENT_TYPE_APP_FORM_URLENCODED ) ) {
175
- dbg . error ( `verify_op_request_body_type: should have header ${ http_utils . CONTENT_TYPE_APP_FORM_URLENCODED } ` +
176
- `in request, ${ headers } ` ) ;
173
+ if ( headers === undefined || ! headers . includes ( http_utils . CONTENT_TYPE_APP_FORM_URLENCODED ) ) {
174
+ dbg . error ( `verify_op_request_body_type: should have header ${ http_utils . CONTENT_TYPE_APP_FORM_URLENCODED } ` +
175
+ `in request, currently the headers are: ${ headers } ` ) ;
177
176
// GAP - need to make sure which error we need to throw
178
177
throw new IamError ( IamError . InvalidParameterValue ) ;
179
178
}
0 commit comments