Skip to content

Make Visma eAccounting API error codes into python native exceptions #13

@Krolken

Description

@Krolken

In addition to normal HTTP error codes Visma eAccounting API returns a standard error response with an additional error code and description.

HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=UTF-8

{
ErrorCode: 4005,
DeveloperErrorMessage: "AuthorizationException - Authorization has been denied for this request.",
ErrorId: "1c296026-489d-434c-b7e9-70401278a086"
}

By using the ErrorCode we could parse the the response and return more helpful python excetions instead of just a VismaAPIException.

The above should raise something like this:

if error_code == 4005:
    raise AuthorizationException('Authorization has been denied for this request')

Available error codes are:

DataModelValidationError - 2000

This error is thrown when any data model validations are broken in the request. See the rules for each POST method on each property.

ResourceNotFound - 3000

This error is thrown when you refer to a specific object that does not exist, eg. customers, suppliers or articles in a request.

FiscalYearDoesNotExist - 3001

This error is thrown when you refer to a specific fiscalyear that does not exist.

AccountNotFound - 3002

This error is thrown when you refer to a specific account that does not exist.

InsufficientApprovalPermission - 3003

This error is thrown when you have insufficient permissions to bookeep an invoice when using supplier invoice approval flow.

Confilct - 4000

This error is thrown when you try to create a object that cannot exist as a duplicate.

CanNotBeDeleted - 4001

This error is thrown when you try to delete a object that cannot be deleted. For example, when a object has dependencies, it cannot be deleted.

CanNotBeCreatedOrUpdated - 4002

This error is thrown when you try to create or update a object that contains one or more invalid properties that prevents it from being created or updated.

StartupGuideNotCompleted - 4003

This error is thrown when you try to make requests towards a company that hasn't completed the startup guide in Visma eAccounting.

CompanyNotActive - 4004

This error is thrown when you try to make requests towards an inactive company.

NotAuthorized - 4005

This error is thrown when you try to make unauthorized requests towards the API.

NoAccessToScopes - 4006

This error is thrown when you try to make requests towards an endpoint which require scopes that you are not authorized with.

PermissionDenied - 4007

This error is thrown when you try to make requests with an authorized user that does not have sufficient permissions for that specific endpoint.

InvalidControlDigit - 4008

This error is thrown when you try to make a request towards an endpoint with ControlDigit validation and the value is invalid.

NoAccessDueToProductVariant - 4009

This error is thrown when you try to make requests towards and endpoint that is not included in the authorized company's product variant.

TooManyRequests - 4010

This error is thrown when you try to more requests than allowed. Read more about this here

NoAccessForAuthenticatedUser - 4011

This error is thrown when the authenticated user does not have access to eAccounting for this company. Give the user access to eAccounting or reauthenticate with a user that have access to eAccounting to solve the issue.

InternalServerError - 5000

This error is thrown when you encounter a error that we have not handled on our side. This can occur if there is a bug in eAccounting. These errors should be reported to us at eaccountingapi@visma.com.

CantReachSystemDependendency - 5001

This error is thrown when you make a request towards and endpoint with external service dependencies, and that dependency is not answering in time. This can occur if a service is down.

QueryParameterError - 6000

This error is thrown when you make a request with $filter parameters and the query is invalid.

InvalidInput - 6001

This error is thrown when you make a request with DateTime properties or filtering and the provided format is wrong.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions