Support » Plugin: License Manager for WooCommerce » different status codes based on error type

  • Resolved beeky2

    (@beeky2)


    Hi Drazen,

    Would be great if we can have different error codes (status) based on error type, at the moment it’s mostly 404, but would be great to have a code for “license key not found”, a code for “reached maximum activation count” and so on.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @beeky2

    Thank you for your message and for using my plugin.

    While developing the REST API endpoints I honestly didn’t put much thought into the error codes. Do you have any suggestions on how this should be implemented?

    Yes,

    You should add status codes maybe starting from 100 and assign for example 101 if the key doesn’t exist, 102 if the max number activation has been reached, 103 if the key is expired.

    Now I have to do calculate on my side if the key is expired, would be great if your plugin can generate a status code for it.

    Also, for don’t know the reason, when I var_dump on my testing website the generated json for error contains only the first item “code:”, while when testing on Postman it appears with all the items.
    The success json has all the items on testing website and Postman.

    That’s really weird

    Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @beeky2

    The error codes should correspond to the HTTP Status Codes, and 100 are informational responses. I think that we should stick to the 4xx and/or 5xx numbers, as described here:

    https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

    What do you think?

    PS: If you show me what your code looks like I might be able to help with the issue you’ve described.

    starting from 4xx is fine, the most important thing is that they have different numbers so I can assign different translated error messages from my side. At the moment the errors are identified from different messages in english from you plugin json.

    2: this is the way I retrive the json, in case of success all the items are displayed, in case of error only the first item “code” is displayed:

    
    // this is for Debug
    $decoded 	  = $this->get_key_access();
    var_dump($decoded);
    
    public function get_key_access() {
    		$url          = SWAL_WEBSITE_URL . "/wp-json/lmfwc/v2/licenses/$this->key?consumer_key=$this->ck&consumer_secret=$this->cs";
    		$decoded_body = $this->get_decoded_body( $url );
    
    		return $decoded_body;
    	}
    
    /**
         * 
    	 * Utility function to get json body from URL request
    	 * 
    	 */
    	public function get_decoded_body( $url ) {
    
    			$response = wp_remote_get( $url );
    			if ( 200 === (int) wp_remote_retrieve_response_code( $response ) ) {
    				$body         = wp_remote_retrieve_body( $response );
    				$decoded_body = json_decode( $body, true );
    			}
    		if ( ! empty( $decoded_body ) ) {
    			return $decoded_body;
    		}
    
    		return false;
    	}
    
    
    Plugin Author Drazen Bebic

    (@drazenbebic)

    @beeky2

    The status codes probably won’t change much. The meaning of HTTP status codes is firmly set and defined (i.e. 403 = forbidden, 404 = not found, etc.).

    What I can do is modify the “code” parameter so that is unique for every error. Currently it just says “lmfwc_rest_data_error” most of the time. Here’s a screenshot of what I mean:

    https://snipboard.io/Q82O3F.jpg

    As for your error, I would recommend debugging the $response variable to check what the server is returning at all.

    I was assuming that data->status on error json had the same meaning of data->status on success json.

    But yes, you can actually modify the code parameter to make unique for every error. That would be great.

    Plugin Author Drazen Bebic

    (@drazenbebic)

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.