I'm using sthttprequest and php for webserver communication in my apps. This is a sample request:
-(void)GetSomething:(NSString*)Username :(NSString*)Password {
__block STHTTPRequest *up = [STHTTPRequest requestWithURLString:[NSString stringWithFormat:@"%@%@",PATHSERVER,@"getsomething.php"]];
up.POSTDictionary = @{@"username":Username,@"password":Password};
up.completionBlock = ^(NSDictionary *headers, NSString *body) {
//my result data
};
up.errorBlock = ^(NSError *error) {
NSLog(@"-error description and error code- %@", [error localizedDescription]);
};
[up startAsynchronous];
}
When a condition occurs i wanna output an error in my php page to display an alert in sthttprequest error's block:
up.errorBlock = ^(NSError *error) {
NSLog(@"-error description and error code- %@", [error localizedDescription]);
};
It is possible to force a custom code error from a php page to achive this behaviour? Something like:
<?php echo $custom_error_code; ?>
up.errorBlock = ^(NSError *error) {
if (error.code==1300){
//this is the code i have set in php
}
};
I don't want an already assigned error like 503,500,ect... because i risk to display the alert to the user when it makes not sense. I want to use the block error and not a simple string in the completionBlock for pratical reasons.
EDIT
I have found this answer here in stackoverflow Can we create custom HTTP Status codes?
So i can create custom error code where the number isn't already assigned , what i have to respect is the class number 4xx or 5xx. Now my problem is to output a custom error code like "475" from a php page. The method
header_status(475);
dosen't work for me.
this answer https://stackoverflow.com/a/23190950/3057259 give me the right way to post a custom error code to sthttprequest that recognize it correctly.