lib/OctoPrint/OctoPrintAPI.cpp
int OctoprintApi::extractHttpCode(String statusCode, String body) {
  if (_debug) {
    Serial.print("\nStatus code to extract: ");
    Serial.println(statusCode);
  }
  int firstSpace = statusCode.indexOf(" ");
  int lastSpace  = statusCode.lastIndexOf(" ");
  if (firstSpace > -1 && lastSpace > -1 && firstSpace != lastSpace) {
    String statusCodeALL     = statusCode.substring(firstSpace + 1);             //"400 BAD REQUEST"
    String statusCodeExtract = statusCode.substring(firstSpace + 1, lastSpace);  //May end up being e.g. "400 BAD"
    int statusCodeInt        = statusCodeExtract.toInt();                        //Converts to "400" integer - i.e. strips out rest of text characters "fix"
    if (_debug and statusCodeInt != 200 and statusCodeInt != 201 and statusCodeInt != 202 and statusCodeInt != 204) {
      Serial.print("\nSERVER RESPONSE CODE: " + String(statusCodeALL));
      if (body != "")
        Serial.println(" - " + body);
      else
        Serial.println();
    }
    return statusCodeInt;
  } else
    return -1;
}
/**
 * Extract the HTTP header response code. Used for error reporting - will print in serial monitor any non 200 response codes (i.e. if something has gone wrong!).
 * Thanks Brian for the start of this function, and the chuckle of watching you realise on a live stream that I didn't use the response code at that time! :)
 * */
Extract the HTTP header response code. Used for error reporting - will print in serial monitor any non 200 response codes .
Thanks Brian for the start of this function, and the chuckle of watching you realise on a live stream that I didn't use the response code at that time.
Extract the HTTP header response code . Used for error reporting - will print in serial monitor any non 200 response codes . Thanks Brian for the start of this function and the chuckle of watching you realise on a live stream that I didn ' t use the response code at that time .
int OctoprintApi::extractHttpCode(String statusCode, String body) {
  if (_debug) {
    Serial.print("\nStatus code to extract: ");
    Serial.println(statusCode);
  }
  int firstSpace = statusCode.indexOf(" ");
  int lastSpace  = statusCode.lastIndexOf(" ");
  if (firstSpace > -1 && lastSpace > -1 && firstSpace != lastSpace) {
    String statusCodeALL     = statusCode.substring(firstSpace + 1);             
    String statusCodeExtract = statusCode.substring(firstSpace + 1, lastSpace);  
    int statusCodeInt        = statusCodeExtract.toInt();                        
    if (_debug and statusCodeInt != 200 and statusCodeInt != 201 and statusCodeInt != 202 and statusCodeInt != 204) {
      Serial.print("\nSERVER RESPONSE CODE: " + String(statusCodeALL));
      if (body != "")
        Serial.println(" - " + body);
      else
        Serial.println();
    }
    return statusCodeInt;
  } else
    return -1;
}
int OctoprintApi :: extractHttpCode ( String statusCode , String body ) { if ( _debug ) { Serial . print ( " \n " ) ; Serial . println ( statusCode ) ; } int firstSpace = statusCode . indexOf ( " " ) ; int lastSpace = statusCode . lastIndexOf ( " " ) ; if ( firstSpace > -1 && lastSpace > -1 && firstSpace != lastSpace ) { String statusCodeALL = statusCode . substring ( firstSpace + 1 ) ; String statusCodeExtract = statusCode . substring ( firstSpace + 1 , lastSpace ) ; int statusCodeInt = statusCodeExtract . toInt ( ) ; if ( _debug and statusCodeInt != 200 and statusCodeInt != 201 and statusCodeInt != 202 and statusCodeInt != 204 ) { Serial . print ( " \n " + String ( statusCodeALL ) ) ; if ( body != " " ) Serial . println ( " " + body ) ; else Serial . println ( ) ; } return statusCodeInt ; } else return -1 ; }
Extract the HTTP header response code.
Extract the HTTP header response code .
//"400 BAD REQUEST" //May end up being e.g. "400 BAD" //Converts to "400" integer - i.e. strips out rest of text characters "fix"