API Request - printer offline = 409

Hello.

I wrote some java script lines. The target is: Read the printer state and temp and display it as overlay in an video stream.

Works fine but if the printer is not connected to the octoprint host the API reports only "409 Conflict".

Would not it be more effective if the API reports the real actual state? In my case:

{
  "sd": {
    "ready": false
  },
  "state": {
    "flags": {
      "cancelling": false,
      "closedOrError": false,
      "error": false,
      "finishing": false,
      "operational": false,
      "paused": false,
      "pausing": false,
      "printing": false,
      "ready": false,
      "resuming": false,
      "sdReady": false
    },
    "text": "not connected"
  },
  "temperature": {}
}

I just do not understand why an unconnected printer is reported with 409.

Grüße,
Christian

It's not a terrible idea.

And yet, 409 sounds like it's the status code for this particular state.

409 sounds there is an problem with the API (or Host). But the host works fine. Just my opinion.

409 with just a simple text body is used in a number of similat cases in OctoPrint. On other example is if you try to upload a gcode file with the same filename as the currently printing job, or trying to upload to sd when no sd card is inserted into the printer.

https://httpstatuses.com/409

4×× Client Error
409 Conflict

The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.

You cannot query the status of a printer if no printer is connected. You can change this though by connecting to a printer. Even a 404 would have been practical here.

In a case like this where you're writing an interface, feel free to trap the 409 and then mockup any sort of JSON response that you'd rather see.

In my octo-client Node module, I just do something like this (look for 204 below):

      var req = http.request(options, function(resp) {
        resp.setEncoding('utf8');
        var data = '';
        resp.on('data',   function(chunk)  {data += chunk;});
        resp.on('end',    function()       {
          if (resp.statusCode == 204) return callback('{"status": "Success"}');
          return callback(data);
        });  // resp.on('end')
      });    // var req = ...

I'm just mocking up what I can more easily work with in the code that calls this.

Thank you. Yes i catch now the 409 Error and change it to me "custom" Text.
image

You cannot query the status of a printer if no printer is connected.

Not if i query the printer directly, yes. But the request is send to the host and "disconnected" is also a state. I can not say that 409 is wrong. But if the response is "disconnected" or "offline" .. is more correct in my personal opinion. Anyway. It works now. Thank you

1 Like