INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: MCWS should 400 when given a bad request (and it should log something)  (Read 782 times)

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4276

currently, if you have a typo in a URL then MC responds with a 500 and there's no info in the logs to hint at what happened

it should a) respond with a 400 (so it's obvious the fault is behind the keyboard) and b) log something to say what happened

e.g.

MCWS/v1/Command/MCC?Command=22000  produces a 500 but Command/MCC is wrong so it should 400 instead
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42446
  • Shoes gone again!
Re: MCWS should 400 when given a bad request (and it should log something)
« Reply #1 on: January 08, 2024, 07:15:02 am »

I get a response with this when I try your command:
<Response Status="Failure" Information="Function 'Command/MCC' not found."/>
Logged
Matt Ashland, JRiver Media Center

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4276
Re: MCWS should 400 when given a bad request (and it should log something)
« Reply #2 on: January 08, 2024, 07:34:56 am »

Yes but the http status code is what I am referring to, it should not 500 at this point
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42446
  • Shoes gone again!
Re: MCWS should 400 when given a bad request (and it should log something)
« Reply #3 on: January 08, 2024, 08:11:56 am »

If we switch to responding with a 404 the error is no longer shown since the browser doesn't render the page.  So I think the current approach is better.
Logged
Matt Ashland, JRiver Media Center

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4276
Re: MCWS should 400 when given a bad request (and it should log something)
« Reply #4 on: January 08, 2024, 08:14:47 am »

One might argue that 404 is technically more correct for a rest API but mcws isn't a rest API so that's not relevant before, it should return 400 not 404 in case because the request itself is bad

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

Warning: The client should not repeat this request without modification.

This warning is exactly correct

500 is

server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

There's nothing unexpected here so this error code is not appropriate

Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42446
  • Shoes gone again!
Re: MCWS should 400 when given a bad request (and it should log something)
« Reply #5 on: January 08, 2024, 08:23:54 am »

I'll try switching to 400 for MC32.  Testing appreciated once it ships.  Thanks.
Logged
Matt Ashland, JRiver Media Center
Pages: [1]   Go Up