Écrire une réponse

Veuillez écrire votre message et l'envoyer

Cliquez dans la zone sombre de l'image pour envoyer votre message.

Retour

Résumé de la discussion (messages les plus récents en premier)

ccavelier
2026-01-30 10:22:09

Merci pour ces précisions.
Je vais en tenir compte dans mon intégration.

Merci !

plg
2026-01-30 10:12:43

Bonjour Christophe,

J'ai regardé et dans le code de l'API côté Piwigo, on fait souvent ce genre de choses :

Code:

return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid search_id input parameter.');
return new PwgError(WS_ERR_MISSING_PARAM, 'rank is missing');
return new PwgError(404, 'image_id not found');
return new PwgError(500, 'error during buffer directory creation');
return new PwgError(405, 'The image (file) is missing');
return new PwgError(403, 'Invalid security token');
return new PwgError(401, 'formats are disabled');

Sachant que :

Code:

define( 'WS_ERR_INVALID_METHOD',  501 );
define( 'WS_ERR_MISSING_PARAM',   1002 );
define( 'WS_ERR_INVALID_PARAM',   1003 );

et que :

Code:

class PwgError
{
  private $_code;
  private $_codeText;

  function __construct($code, $codeText)
  {
    if ($code>=400 and $code<600)
    {
      set_status_header($code, $codeText);
    }

    $this->_code = $code;
    $this->_codeText = $codeText;
  }

  function code() { return $this->_code; }
  function message() { return $this->_codeText; }
}

Si le code est entre 400 et 600, on l'utilise dans le header. Sinon c'est code 200 et on ne trouve le code d'erreur que dans le body.

J'ai trouvé pas mal d'exemples avec un retour en 404 :

Code:

~/git/Piwigo/include/ws_functions[16.x|⚑49] % grep 404 *
pwg.categories.php:      return new PwgError(404, 'cat_id {'.implode(',', $missing_cat_ids).'} not found');
pwg.categories.php:    return new PwgError(404, 'category_id not found');
pwg.categories.php:    return new PwgError(404, 'category_id not found');
pwg.categories.php:    return new PwgError(404, 'category_id not found');
pwg.categories.php:    return new PwgError(404, 'image_id not found');
pwg.categories.php:    return new PwgError(404, 'category_id not found');
pwg.categories.php:    return new PwgError(404, 'category_id not found');
pwg.images.php:    return new PwgError(404, 'image_id not found');
pwg.images.php:    return new PwgError(404, 'Invalid image_id or access denied');
pwg.images.php:    return new PwgError(404, 'image_id not found');
pwg.images.php:    return new PwgError(404, 'This image is not associated to this category');
pwg.images.php:    return new PwgError(404, "image_id not found");
pwg.images.php:      return new PwgError(404, 'image_id not found');
pwg.images.php:      return new PwgError(404, 'image_id not found');
pwg.images.php:        return new PwgError(404, __FUNCTION__.' : image_id not found');
pwg.images.php:      return new PwgError(404, __FUNCTION__.' : image_id not found');
pwg.images.php:    return new PwgError(404, 'No format found for the id(s) given');
pwg.images.php:    return new PwgError(404, 'image_id not found');
pwg.images.php:    return new PwgError(404, 'image_id not found');
pwg.images.php:    return new PwgError(404, 'category_id not found');
pwg.users.php:    return new PwgError(404, 'image_id not found');
pwg.users.php:    return new PwgError(404, 'image_id not found');
ccavelier
2026-01-30 09:58:01

Bonjour,

J'utilise l'API pwg.images.getInfo pour récupérer des infos sur mes images mais si on lui passe une image_id inconnu, l'API renvoie un 404 avec un body de ce type:
{
    "stat": "fail",
    "err": 404,
    "message": "image_id not found"
}

Il faut alors utiliser le error stream pour récupérer correctement le message.

Les autres méthodes de l'API renvoie un 200 dans ce cas, ce qui est logique car il n'y a pas d'erreur technique mais une erreur fonctionnelle.
Je m'attendrais plutôt d'avoir un HTTP Code à 200 et un err spécifique

Est-ce que c'est volontaire ou est-ce un bug de cette API ?
Si c'est volontaire, est-ce qu'il y a d'autres API qui utilise ce pattern ?

Ca serait intéressant dans l'API reflection.getMethodDetails, d'avoir une section qui décrit le retour attendu.
A titre d'exemple pour reflection.getMethodDetails, si on passe un methodName inconnu, on recoit:
HTTP Code = 200
Body:
{
    "stat": "fail",
    "err": 1003,
    "message": "Requested method does not exist"
}

Merci,
Christophe

Pied de page des forums

Propulsé par FluxBB

github linkedin newsletter Piwigo.org © 2002-2026 · Contact